#include using namespace std; __int128 n, m; const __int128 mod = 1e9 + 7; __int128 aa, bb; inline __int128 mpow(__int128 a, __int128 b, __int128 c) { __int128 r = 1; while (b) { if (b & 1) { r = r * a % c; } a = a * a % c; b >>= 1; } return r; } __int128 S(__int128 n) { if (n == 1) return bb; __int128 nn; nn = n / 2; __int128 ans1 = n * n * n * bb + (n - 1) * n * n * aa; __int128 ans2 = 18 * nn * nn * aa + 7 * S(nn); return min(ans1, ans2); } inline __int128 read() { __int128 x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline void print(__int128 x) { if (x < 0) { putchar('-'); x = -x; } if (x > 9) print(x / 10); putchar(x % 10 + '0'); } int main() { int TT; ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> TT; while (TT--) { long long nn, a, b; cin >> nn >> a >> b; n = nn; aa = a; bb = b; __int128 ans = S(n); long long anss = ans%mod; cout << anss << endl; } return 0; }