#include using namespace std; typedef long long LL; typedef __int128 LLL; const int MAXN=1e6+10; const LL INF=1e15+7; const int mod=1e9+7; //int n,m; LL v1,v2; LLL solve(LLL n){ LLL tmp1=n*n*n*(v1+v2)-n*n*v1; if (n%2==1) return tmp1; else{ LLL tmp2=n*n*9/2*v1+solve(n/2)*7; return min(tmp1,tmp2); } } int main(){ int T; scanf("%d",&T); while(T--){ LL n; scanf("%lld%lld%lld",&n,&v1,&v2); LLL ans=solve(n); ans%=mod; printf("%lld\n",(LL)ans); } return 0; }