#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long power(long long x, long long y) {
  long long ans = 1ll;
  long long ret = x;
  while (y) {
    if (y & 1ll) ans = (ans * ret) % mod;
    ret = (ret * ret) % mod;
    y /= 2ll;
  }
  return ans;
}
int32_t main() {
  long long a, b, n, x;
  cin >> a >> b >> n >> x;
  if (n == 1) return cout << (a * x + b) % mod << endl, 0;
  if (a == 1) return cout << (x + ((n) % mod) * b) % mod << endl, 0;
  long long d =
      (((b * ((power(a, n) - 1ll) + mod)) % mod) * power(a - 1ll, mod - 2ll)) %
      mod;
  long long c = (power(a, n) * x) % mod;
  return cout << (c + d) % mod << endl, 0;
}
