#include using namespace std; #define N 100005 #define P 1000000007 #define Inv4 250000002 int T; long long n; int a,b; long long f[N]; long long l; long long Calc(long long x){return (x%P*x%P*x%P*b%P+x%P*x%P*x%P*a%P-x%P*x*a)%P;} long long Dfs(long long x) { if (x==l) { return Calc(x); } else { long long ans=Dfs(x/2)*7%P+x%P*x%P*Inv4%P*18%P*a%P; ans%=P; return ans; } } int main() { scanf("%d",&T); while (T--) { scanf("%I64d%d%d",&n,&a,&b); long long x=1; l=1; f[0]=b; for (int i=1;(1ll<=f[i]) break; f[i]=tmp; l=x; } long long ans=Dfs(n); while (ans