#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
struct matrix {
  long long a[2][2];
  matrix() {
    int i, j;
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 2; j++) a[i][j] = 0;
    }
  }
  matrix operator*(matrix x) {
    int i, j, k;
    matrix ans;
    for (i = 0; i < 2; i++) {
      for (j = 0; j < 2; j++) {
        for (k = 0; k < 2; k++) {
          ans.a[i][k] = (ans.a[i][k] + a[i][j] * x.a[j][k]) % mod;
        }
      }
    }
    return ans;
  }
};
matrix pw(matrix a, long long b) {
  matrix ans;
  int i, j;
  for (i = 0; i < 2; i++) ans.a[i][i] = 1;
  while (b) {
    while (!(b & 1)) {
      a = a * a;
      b >>= 1;
    }
    b--;
    ans = ans * a;
  }
  return ans;
}
long long a, b, n, x;
int main() {
  cin >> a >> b >> n >> x;
  matrix m;
  m.a[0][0] = a;
  m.a[0][1] = b;
  m.a[1][0] = 0;
  m.a[1][1] = 1;
  m = pw(m, n);
  long long ans = (m.a[0][0] * x + m.a[0][1]) % mod;
  cout << ans;
}
