#include using namespace std; //快速幂 typedef long long LL; const int mod = 200907; int qmi(int a, int k) { int res = 1; while (k) { if (k & 1) res = (LL)res * a % mod; a = (LL)a * a % mod; k >>= 1; } return res; } int main() { int n; scanf("%d", &n); while (n--) { int a, b, c, k; scanf("%d%d%d%d", &a, &b, &c, &k); if (a + c == b * 2) //等差 printf("%lld\n", (a + (b - a) * (LL)(k - 1)) % mod); else //等比 printf("%lld\n", (LL)a * qmi(b / a, k - 1) % mod); } return 0; }