#include <bits/stdc++.h>
using namespace std;
long long pw(long long b, long long e) {
  long long a = 1;
  while (e > 0) {
    if (e & 1) {
      a = a * b % 1000000007ll;
    }
    b = b * b % 1000000007ll;
    e >>= 1;
  }
  return a;
}
long long inv(long long x) { return pw(x, 1000000007ll - 2); }
int main() {
  ios::sync_with_stdio(0);
  long long A, B, n, x;
  while (cin >> A >> B >> n >> x) {
    if (A == 1) {
      cout << (x + n % 1000000007ll * B % 1000000007ll) % 1000000007ll << "\n";
    } else {
      long long An = pw(A % 1000000007ll, n);
      long long ans = An * x % 1000000007ll +
                      (An - 1) * B % 1000000007ll * inv(A - 1) % 1000000007ll;
      cout << ans % 1000000007ll << "\n";
    }
  }
  return 0;
}
