//#include #pragma GCC optimize(3) #include #include #include #include #include #include #include #include #include #include #include #include //#include #define X first #define Y second #define PB push_back #define MP make_pair #define EB emplace_back #define mset(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0) #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) using namespace std; typedef long long ll; #ifdef local #define dbg(args...) do { cout << "\033[32;1m" << #args << " -> "; err(args); } while (0) void err() { cout << "\033[39;0m" << endl; } template class T, typename t, typename... Args> void err(T a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); } template void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(...) #endif template inline bool scan(T&ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-' and (c<'0' or c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0' and c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template inline void out(T x) { if(x>9) out(x/10); putchar(x%10+'0'); } int _ = 0; void testcase() { cout << "Case " << (++_) << ": "; } const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const long double eps = 1e-6; const int mod = 1e9+7; //const int maxn = 3e6; const int N = (1<<20)+5; const int M = 710; using pii = pair; using pll = pair; #define lson rt<<1 #define rson rt<<1|1 using LL = __int128; map mp; ll a,b; LL cal(ll n){ if(mp.count(n)){ return mp[n]; } LL ans = (LL)n*n*n*b + (LL)n*n*(n-1)*a; if(!(n&1)){ ans = min(ans, (LL)18*(n/2)*(n/2)*a + 7*cal(n/2)); } mp[n] = ans; return ans; } void work() { ll n; cin >> n >> a >> b; mp.clear(); LL ans = cal(n); ll res = ans%mod; cout <> t; for(;t--;) work(); return 0; }