usingnamespace std; typedeflonglong ll; ll mod = 1e9 + 7, n, K, A, B, m, mod1 = 1e9 + 6;
ll power(ll a, ll b){ return b ? power(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
structmat { ll m[2][2]; };
mat mul(mat a, mat b){ mat c; memset(c.m, 0, sizeof(c.m)); for (int i = 0; i < n; i++) { for (int k = 0; k < n; k++) { if (a.m[i][k] == 0) continue; for (int j = 0; j < n; j++) { c.m[i][j] = (c.m[i][j] + a.m[i][k] * b.m[k][j]) % mod1; if (c.m[i][j] < 0) c.m[i][j] += mod1; } } } return c; }
mat mat_pow(mat a, int k){ mat ans; ans.m[0][0] = 1, ans.m[1][0] = 1; ans.m[0][1] = ans.m[1][1] = 0; while (k > 0) { if (k & 1) ans = mul(a, ans); a = mul(a, a); k >>= 1; } return ans; }
intmain(){ n = 2; cin >> A >> B >> m >> K; mat a; a.m[0][0] = A, a.m[0][1] = B; a.m[1][0] = 1, a.m[1][1] = 0; if (K <= 2) cout << m; else { mat ans = mat_pow(a, K - 2); ll u = ans.m[0][0]; cout << power(m, u); } return0; }