#include using namespace std; typedef long long ll; const int mod=1e9+7; ll n; int t,a,b; inline __int128 read() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } inline void print(__int128 x) { if(x<0){putchar('-');x=-x;} if(x>9) print(x/10); putchar(x%10+'0'); } __int128 getans(ll n){ if(n==1)return b; __int128 ans=min((__int128)n*n*n*b+(__int128)n*n*(n-1)*a,(18*((__int128)n/2)*(n/2)*a+7*getans(n/2))); return ans; } int main (){ cin>>t; while(t--){ cin>>n; cin>>a>>b; print(getans(n)%mod); cout<