#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
const ll inf = 5e18;
const ll mod = 1e9 + 7;
ll res, ans;
ll a[N];
ll po(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
void solve() {
  ll A, B, n, x;
  cin >> A >> B >> n >> x;
  ans = po(A, n) % mod;
  if (A == 1) {
    cout << (n % mod * B + x) % mod << endl;
    return;
  }
  ans = (((ans * x) % mod +
          ((((ans - 1) * B % mod) % mod) * po(A - 1, mod - 2)) % mod)) %
        mod;
  cout << ans;
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
