#include using namespace std; #define mod 1000000007 typedef __int128 ll; ll read() { ll x=0,f=1; char ch=getchar(); while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();} while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();} return x*f; } ll n,a,b; ll Tx(ll n) { ll res1=0,res2=0; if(n%2==0) return min(7*Tx(n/2)+18*(n/2)*(n/2)*a,n*n*n*b+(n-1)*n*n*a); return n*n*n*b+(n-1)*n*n*a; } void print(ll x) { if(x>9) print(x/10); putchar(x%10+'0'); } int main() { int T; cin>>T; while(T--) { n=read();a=read();b=read(); print(Tx(n)%mod); puts(""); } return 0; }