/** * Author: AcFunction * Date: 2019-08-25 13:50:57 * Email: 3486942970@qq.com **/ #include #define ll long long #define db double #define PII pair #define pb push_back #define fi first #define se second using namespace std; const ll mod = 1e9 + 7; const ll INF = 1e18; int T; ll ans = INF; int mindep; pair calc(ll n, ll a, ll b) { db P = 1e100; db ret = 0; ll o = 0; ll t = n % mod; ret = 0; ret = 1.0 * n * n * n * b; ret += 1.0 * (n - 1) * n * n * a; ll tmp = 0; tmp = t * t % mod * t % mod * b % mod; tmp += (t - 1) * t % mod * t % mod * a % mod; tmp %= mod; o = tmp; if(ret < P) { P = ret; } if(n % 2 == 1) { return {ret, o}; } else { pair X = calc(n / 2, a, b); ll t = n / 2 % mod; db x = 1.0 * (X).fi * 7 + 18.0 * (n / 2) * (n / 2) * a; tmp = ((X).se * 7 % mod + 18 * t % mod * t % mod * a % mod) % mod; if(x < P && x < ret) { P = x; ans = tmp; o = tmp; } return {min(ret, x), o}; } } int main() { scanf("%d", &T); while(T --> 0) { ll n, a, b; scanf("%I64d %I64d %I64d", &n, &a, &b); printf("%I64d\n", (ll)calc(n, a, b).se); } return 0; }