#include #define lg2(x) (63 - __builtin_clzll(x)) typedef long long ll; typedef std::pair pr; const int N = 50, mod = 1000000007; int a, b; pr f[N]; inline pr operator + (const pr &A, const pr &B) {return pr(A.first + B.first, (A.second + B.second) % mod);} inline pr operator * (const pr &A, ll B) {return pr(A.first * B, A.second * B % mod);} inline pr get(ll n) { return pr( (n * (double)b + (n - 1) * (double)a) * n * n, (n * b % mod + (n - 1) * a % mod) % mod * n % mod * n % mod ); } inline pr dc(ll n) { return pr( (double)n * n * 4.5 * a, n % mod * n % mod * 500000008ll % mod * a % mod ); } int main() { int T, i; ll n; for (scanf("%d", &T); T; --T) { scanf("%I64d%d%d", &n, &a, &b); *f = pr(b, b); for (i = 1; i <= 32; ++i) f[i] = std::min(get(1ll << i), dc(1ll << i) + f[i - 1] * 7); printf("%d\n", f[lg2(n)].second); } return 0; }