#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
int mod_pow(int x, long long p) {
  int ans = 1;
  for (int i = 0; i < 63; i++) {
    if (p & (1LL << i)) {
      ans = ans * 1LL * x % MOD;
    }
    x = x * 1LL * x % MOD;
  }
  return ans;
}
tuple<int, int, int> xgcd(int a, int b) {
  int cf[2][2] = {{1, 0}, {0, 1}};
  while (b) {
    int z = a / b;
    a -= b * z;
    cf[0][0] -= cf[1][0] * z;
    cf[0][1] -= cf[1][1] * z;
    swap(cf[0], cf[1]);
    swap(a, b);
  }
  return {a, cf[0][0], cf[0][1]};
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int A, B, x;
  long long n;
  cin >> A >> B >> n >> x;
  int ans;
  if (A == 1) {
    ans = (n % MOD * B + x) % MOD;
  } else {
    int An = mod_pow(A, n);
    ans = x * 1LL * An % MOD;
    int inv = get<1>(xgcd(A - 1, MOD));
    while (inv < 0) inv += MOD;
    An = ((An - 1) % (A - 1) > 0 ? (An - 1) * 1LL * inv % MOD
                                 : (An - 1) / (A - 1));
    ans += B * 1LL * An % MOD;
    ans %= MOD;
  }
  cout << ans;
}
