//12252024832524 #include #include #define Min(x,y) (xy?x:y) using namespace std; typedef unsigned __int128 LL; const int MAXN = 10005; const int MOD = 1e9 + 7; LL n,a,b,ans; LL Read() { LL x1 = 0;char c1 = getchar(); while(c1 > '9' || c1 < '0')c1 = getchar(); while(c1 >= '0' && c1 <= '9'){x1 = (x1*10) + (c1^48);c1 = getchar();} return x1; } void Put(LL x) { if(x > 9) Put(x/10); putchar(x%10^48); } LL dfs(LL x) { if(x == 1) return b; LL t = 18*(x>>1)*(x>>1)*a + 7*dfs(x>>1); t = Min(t,x*x*x*b + (x-1)*x*x*a); return t; } int main() { // freopen(".in","r",stdin); // freopen(".out","w",stdout); for(LL T = Read(); T ;-- T) { n = Read(); a = Read(); b = Read(); Put(dfs(n) % MOD); putchar('\n'); } return 0; }