#include <bits/stdc++.h>
using namespace std;
template <class X, class Y>
void minimize(X &x, const Y &y) {
  if (x > y) x = y;
}
template <class X, class Y>
void maximize(X &x, const Y &y) {
  if (x < y) x = y;
}
template <class T>
T Abs(const T &x) {
  return (x < 0 ? -x : x);
}
const int mod = (int)1e9 + 7;
int pw(int x, long long k) {
  int res = 1;
  int mul = x;
  while (k > 0) {
    if (k & 1) res = 1LL * res * mul % mod;
    mul = 1LL * mul * mul % mod;
    k >>= 1;
  }
  return (res);
}
int inverse(int x) { return (pw(x, mod - 2)); }
int main(void) {
  int a, b, x;
  long long n;
  cin >> a >> b >> n >> x;
  if (a == 1)
    cout << (x + n % mod * b) % mod << endl;
  else
    cout << (1LL * pw(a, n) * x % mod +
             1LL * (pw(a, n) - 1 + mod) * inverse(a - 1) % mod * b) %
                mod
         << endl;
  return 0;
}
