#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 1e6 + 5;
const long long mod = 1e9 + 7;
struct matrix {
  vector<vector<long long>> v;
  int n;
  int m;
  matrix() {}
  matrix(int n, int m) {
    this->n = n;
    this->m = m;
    v.resize(n);
    for (int i = 0; i < n; i++) {
      v[i].resize(m);
    }
  }
  pair<int, int> dim() const { return {n, m}; }
  bool operator==(const matrix &B) const {
    if (dim() != B.dim()) return false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (v[i][j] != B.v[i][j]) return false;
      }
    }
    return true;
  }
  void print() const {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cout << v[i][j] << " ";
      }
      cout << endl;
    }
    cout << endl;
  }
};
matrix matmul(matrix &A, matrix &B) {
  pair<int, int> Adim = A.dim();
  pair<int, int> Bdim = B.dim();
  assert(Adim.second == Bdim.first);
  int n = Adim.first;
  int m = Adim.second;
  int p = Bdim.second;
  matrix C(n, p);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < p; j++) {
      for (int k = 0; k < m; k++) {
        C.v[i][j] += A.v[i][k] * B.v[k][j];
        C.v[i][j] %= mod;
      }
    }
  }
  return C;
}
long long a, b, n, x;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> a >> b >> n >> x;
  matrix mat(2, 2);
  mat.v[0][0] = a;
  mat.v[0][1] = b;
  mat.v[1][0] = 0;
  mat.v[1][1] = 1;
  matrix M(2, 2);
  M.v[0][0] = M.v[1][1] = 1;
  while (n > 0) {
    if (n % 2 == 1) {
      M = matmul(M, mat);
    }
    n = n / 2;
    mat = matmul(mat, mat);
  }
  long long ans = (x * M.v[0][0]) % mod + M.v[0][1];
  ans %= mod;
  cout << ans << endl;
  return 0;
}
