#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
struct Matrix {
  int n;
  vector<vector<long long>> a;
  Matrix(int _n) {
    n = _n;
    a = vector<vector<long long>>(n, vector<long long>(n, 0));
  }
  Matrix operator+(Matrix o) {
    Matrix ans(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) ans[i][j] = a[i][j] + o[i][j];
    ans.modulate();
    return ans;
  }
  Matrix operator*(Matrix o) {
    Matrix ans(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++) ans[i][j] += a[i][k] * o[k][j];
    ans.modulate();
    return ans;
  }
  vector<long long>& operator[](int index) { return a[index]; }
  void modulate() {
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) a[i][j] %= MOD;
  }
  void eye() {
    a = vector<vector<long long>>(n, vector<long long>(n, 0));
    for (int i = 0; i < n; i++) a[i][i] = 1;
  }
};
Matrix mod_pow(Matrix a, long long e) {
  Matrix ans(2);
  ans.eye();
  while (e) {
    if (e & 1) ans = ans * a;
    a = a * a;
    e >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long A, B, n, x;
  cin >> A >> B >> n >> x;
  Matrix ans(2);
  ans[0][0] = A;
  ans[0][1] = B;
  ans[1][1] = 1;
  ans = mod_pow(ans, n);
  cout << (ans[0][0] * x + ans[0][1]) % MOD << '\n';
  return 0;
}
