矩阵乘法
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
using namespace std;
LL MMM(int a, int b)
{
return ((a%MOD)*(LL)(b%MOD))%MOD;
}
LL x[4], a[4], t[4];
LL* mult(LL *a,LL *b)
{
x[0]=MMM(a[0],b[0])+MMM(a[1],b[2]);
x[0]%=MOD;
x[1]=MMM(a[0],b[1])+MMM(a[1],b[3]);
x[1]%=MOD;
x[2]=MMM(a[2],b[0])+MMM(a[3],b[2]);
x[2]%=MOD;
x[3]=MMM(a[2],b[1])+MMM(a[3],b[3]);
x[3]%=MOD;
return x;
}
void print(LL *a)
{
cout<<a[0]<<" "<<a[1]<<endl;
cout<<a[2]<<" "<<a[3]<<endl;
}
LL e[4]={1,0,0,1};
LL s[4]={0,-1,1,1};
void eq(LL *a,LL *b)
{
for (int i=0;i<4;i++) a[i]=b[i];
}
int main()
{
int T, p;
long long f1, f2;
cin>>T;
for(int I=1; I<=T; I++){
cin>>f1>>f2;
cin>>p;p--;
eq(t, s);
if (p%2==0){
eq(a, e);
} else {
eq(a, t);
}
p=p>>1;
while (p>0) {
eq(t,mult(t,t));
if (p%2==1){eq(a,mult(a,t));}
p=p>>1;
}
long long ans = ((f1*a[0]+MOD)%MOD + (f2*a[2]+MOD)%MOD+MOD)%MOD;
if (ans<0) {cout<<ans+MOD<<endl; }else{cout<<ans<<endl;}
}
return 0;
}