#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-12;
const long double pi = acos(-1);
const int MOD = int(1e9) + 7;
long long modI(long long a) {
  long long b = MOD, b0 = b, t, q;
  long long x0 = 0, x1 = 1;
  if (b == 1) return 1;
  while (a > 1) {
    q = a / b;
    t = b, b = a % b, a = t;
    t = x0, x0 = x1 - q * x0, x1 = t;
  }
  if (x1 < 0) x1 += b0;
  return x1;
}
long long power(long long a, long long b) {
  long long ans = 1;
  while (b) {
    if (b & 1) ans *= a, ans %= MOD;
    a *= a;
    a %= MOD;
    b >>= 1;
  }
  return ans;
}
void solve() {
  long long A, B, n, x;
  cin >> A >> B >> n >> x;
  if (!n) {
    cout << x << "\n";
    return;
  } else if (A == 1) {
    n %= MOD;
    cout << (x + n * B) % MOD << "\n";
    return;
  }
  long long pw = power(A, n);
  pw %= MOD;
  long long ans = pw * x;
  ans %= MOD;
  long long X = (pw - 1) + MOD;
  X %= MOD;
  long long S = (X * modI((A - 1)));
  S %= MOD;
  long long sec = B * (S);
  cout << (ans + sec) % MOD << "\n";
}
int main() { solve(); }
