#include using namespace std; typedef long long ll; const int M=1000000007; ll f[123456],g[123456],p,q,_,n,a,b; ll calc(ll n,ll a,ll b){ if (n<=31) return f[n]%M; return (7*calc(n/2,a,b)+18*(n/2)%M*(n/2)%M*a)%M; } int main(){ cin >> _; while (_--){ cin >> n >> a >> b; for (ll i=1;i<=31;i++){ f[i]=i*i*i*b+(i-1)*i*i*a; if (i%2==0) f[i]=min(f[i],7*f[i/2]+18*(i/2)*(i/2)*a); } cout << calc(n,a,b) << endl; } }