#include #include #include using namespace std; typedef __int128 lint; lint a, b; __int128 dfs(lint n) { __int128 ans = (__int128)n * n * n * b + (__int128)(n-1) * n * n * a; if (!(n & 1)) { n >>= 1; ans = min(ans, (__int128)18 * n * n * a + 7 * dfs(n)); } return ans; } template void read(T& x) { x = 0; bool neg = 0; char c; while(!isdigit(c=getchar())) if(c == '-') neg = 1; do { x = x * 10 + c - '0'; } while (isdigit(c=getchar())); if(neg) x = -x; } template void output(T x) { static char buf[100]; static int t; if(x < 0) { putchar('-'); x = -x; } do { buf[t++] = x % 10 + '0'; } while(x /= 10); while(t) putchar(buf[--t]); } int main() { const int p = 1000000007; int T; scanf("%d", &T); while (T--) { __int128 n; read(n); read(a); read(b); output(dfs(n) % p); putchar('\n'); } return 0; }