#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
array<array<long long, 3>, 3> multiply(array<array<long long, 3>, 3>& left,
                                       array<array<long long, 3>, 3>& right) {
  array<array<long long, 3>, 3> result;
  for (auto i = 0; i != 3; i++) {
    for (auto j = 0; j != 3; j++) {
      auto sum = 0ll;
      for (auto k = 0; k != 3; k++) {
        sum += left[i][k] * right[k][j];
      }
      result[i][j] = sum % mod;
    }
  }
  return result;
}
array<array<long long, 3>, 3> exp(array<array<long long, 3>, 3> M,
                                  long long n) {
  array<array<long long, 3>, 3> result = {{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}};
  while (n != 0) {
    if (n % 2 == 1) {
      result = multiply(result, M);
    }
    M = multiply(M, M);
    n /= 2;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long A, B, n, x;
  cin >> A >> B >> n >> x;
  array<array<long long, 3>, 3> M = {{{A, 0, 1}, {1, 0, 0}, {0, 0, 1}}};
  array<long long, 3> N = {{(A * x + B) % mod, x, B}};
  M = exp(M, n);
  cout << (M[1][0] * N[0] + M[1][1] * N[1] + M[1][2] * N[2]) % mod;
  return 0;
}
