#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll N = 1e7;
ll prime[N];
ll tot_fact[N];
ll gcdExtended(ll a, ll b, ll *x, ll *y) {
  if (a == 0) {
    *x = 0, *y = 1;
    return b;
  }
  ll x1, y1;
  ll gcd = gcdExtended(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
ll modInverse(ll b, ll m) {
  ll x, y;
  ll g = gcdExtended(b, m, &x, &y);
  if (g != 1) return -1;
  return (x % m + m) % m;
}
ll power(ll x, ll y) {
  ll temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return (temp % MOD * temp % MOD) % MOD;
  else
    return ((x % MOD * temp % MOD) % MOD * temp % MOD) % MOD;
}
void solve() {
  ll a, b, n, x;
  cin >> a >> b >> n >> x;
  ll tans = power(a, n);
  if (a == 1) {
    cout << (x % MOD + (n % MOD * b % MOD) % MOD) % MOD;
    return;
  }
  ll p = (tans - 1) % MOD;
  ll tt = modInverse(a - 1, MOD);
  ll t = (tt % MOD * p % MOD) % MOD;
  ll ans = ((tans % MOD * x % MOD) % MOD + (b % MOD * t) % MOD) % MOD;
  cout << ans;
}
int main() {
  int t = 1;
  while (t--) solve();
}
