#include <bits/stdc++.h>
long long n, a, b, c, p, q, ans, x;
const int P = 1000000007;
struct matrix {
  long long a[2][2];
} f, g;
matrix cf(matrix u, matrix v) {
  matrix ans;
  int i, j, k;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++) ans.a[i][j] = 0;
  for (i = 0; i <= 1; i++)
    for (j = 0; j <= 1; j++)
      for (k = 0; k <= 1; k++) (ans.a[i][j] += u.a[i][k] * v.a[k][j]) %= P;
  return ans;
}
matrix ksm(long long x) {
  matrix ans;
  if (x == 1) {
    ans = f;
    return ans;
  }
  ans = ksm(x / 2);
  ans = cf(ans, ans);
  if (x % 2) ans = cf(ans, f);
  return ans;
}
int main() {
  scanf("%I64d%I64d%I64d%I64d", &a, &b, &n, &x);
  f.a[0][0] = a;
  f.a[0][1] = 1;
  f.a[1][0] = 0;
  f.a[1][1] = 1;
  g = ksm(n);
  long long ans = (x * g.a[0][0] + b * g.a[0][1]) % P;
  printf("%I64d\n", ans);
}
