等比数列的判断方法:第一项和第三项的乘积=第二项乘积的平方
等差数列的判断方法:第一项和第三项的和=2倍的第二项之和
#include<iostream>
using namespace std;
typedef long long LL;
const int mod=200907;
LL qmi(int a,LL b)
{
LL res=1;
while(b){
if(b&1)res=res*a%mod;
b>>=1;
a=(LL)a*a%mod;
}
return res;
}
int main()
{
int T;
cin>>T;
while(T--){
int a,b,c,k;
scanf("%d%d%d%d",&a,&b,&c,&k);
//等差数列:a+c=2*b 等比数列:a*c=b*b
if(a+c==2*b)printf("%d\n",((a+(LL)(b-a)*(k-1))%mod+mod)%mod);
else printf("%d\n",(a*qmi(b/a,k-1)%mod+mod)%mod);
}
return 0;
}