#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define mm(a,b) memset(a,b,sizeof(a)) typedef long long ll; const long long mod = 1e9 + 7; const int maxn = 2e5 + 10; const ll inf = 1e18; ll a, b; ll f1(ll n) { n %= mod; return (n*n%mod*n%mod*b%mod + n * n%mod*(n - 1) % mod*a%mod) % mod; } ll f2(ll n) { if (n % 2) return f1(n); if (n <= 30 * a / (a + b)) return f1(n); return (18 * (n / 2) % mod*(n / 2) % mod*a%mod + 7 * f2(n / 2) % mod) % mod; } int main() { int t; ll n; cin >> t; while (t--) { scanf("%lld%lld%lld", &n, &a, &b); printf("%lld\n", f2(n)); } }