#include <bits/stdc++.h>
using namespace std;
long long a, b, x, n, ans;
const int mod = 1e9 + 7;
int main() {
  cin >> a >> b >> n >> x;
  while (n) {
    if ((n % 2) != 0) x = (a * x + b) % mod;
    b = (a * b + b) % mod;
    a = (a * a) % mod;
    n /= 2;
  }
  cout << x << endl;
  return 0;
}
