#include<iostream>
using namespace std;
typedef long long LL;
const int mod = 200907;
LL res;
void qpower(int a, int b)
{
res = 1;
while(b)
{
if(b & 1)res = (LL)res * a % mod;
b >>= 1;
a =(LL) a * a % mod;
}
}
int main()
{
int n; cin >> n;
while(n--)
{
int a, b, c, k;cin >> a >> b >> c >> k;
if(a + c == 2 * b)
res = a + (LL)(b - a) * (k - 1) % mod;
else
{
qpower(b / a, k - 1);
res = (LL)res * a % mod;
}
cout << res << endl;
}
return 0;
}