#include
#include <stdio.h>
#include <string.h>
#include <math.h>
#define mod 2147493647
#define ll long long
#define N 8
using namespace std;
struct Matrix
{
int matrix[N][N];
};
Matrix I=
{
1,2,1,4,6,4,1,
1,0,0,0,0,0,0,
0,0,1,4,6,4,1,
0,0,0,1,3,3,1,
0,0,0,0,1,2,1,
0,0,0,0,0,1,1,
0,0,0,0,0,0,1
};
Matrix A=
{
1,0,0,0,0,0,0,
0,1,0,0,0,0,0,
0,0,1,0,0,0,0,
0,0,0,1,0,0,0,
0,0,0,0,1,0,0,
0,0,0,0,0,1,0,
0,0,0,0,0,0,1
};
Matrix multiplicative(Matrix a,Matrix b)///矩阵乘法
{
Matrix res;
memset(res.matrix,0,sizeof(res.matrix));
for(int i = 0 ; i < N ; i++){
for(int j = 0 ; j < N ; j++){
for(int k = 0 ; k < N ; k++){
res.matrix[i][j] += a.matrix[i][k]*b.matrix[k][j];
res.matrix[i][j] %= mod;
}
}
}
return res;
}
Matrix Power(ll m)///矩阵快速幂
{
Matrix base=I,res=A;
while(m)
{
if(m&1)
res=multiplicative(res,base);
base=multiplicative(base,base);
m>>=1;
}
return res;
}
int main()
{
int t;ll n,a,b;
scanf("%d",&t);
while(t–)
{
cin>>n>>a>>b;
a%=mod;
b%=mod;
Matrix B=Power(n-3);
ll ans=(B.matrix[0][0]*b%mod+B.matrix[0][1]*a%mod+16*B.matrix[0][2]%mod
+8*B.matrix[0][3]%mod+4*B.matrix[0][2]%mod+2*B.matrix[0][1]%mod+mod)%mod;
printf("%lld\n",ans);
}
return 0;
}