Consider a linear function f(x) = Ax + B. Let's define g(0)(x) = x and g(n)(x) = f(g(n - 1)(x)) for n > 0. For the given integer values A, B, n and x find the value of g(n)(x) modulo 109 + 7.

Input

The only line contains four integers A, B, n and x (1 ≤ A, B, x ≤ 109, 1 ≤ n ≤ 1018) — the parameters from the problem statement.

Note that the given value n can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.

Output

Print the only integer s — the value g(n)(x) modulo 109 + 7.

Examples

Input

3 4 1 1


Output

7


Input

3 4 2 1


Output

25


Input

3 4 3 1


Output

79
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
const int inf = (1 << 30) - 1;
const long long MOD = 1000000007;
struct Matrix {
  int r, c;
  long long mat[155][155];
  Matrix(int r = 0, int c = 0) { set(r, c); }
  void set(int r, int c) {
    this->r = r;
    this->c = c;
    memset(mat, 0, sizeof(mat));
  }
  void clear() { memset(mat, 0, sizeof(mat)); }
  void output() {
    for (int i = 0; i < r; ++i) {
      for (int j = 0; j < c; ++j) {
        if (j) printf(" ");
        printf("%lld", mat[i][j]);
      }
      printf("\n");
    }
    printf("\n");
  }
  Matrix operator*(const Matrix& u) {
    Matrix ret(r, u.c);
    for (int k = 0; k < c; k++) {
      for (int i = 0; i < r; i++) {
        if (mat[i][k] == 0) continue;
        for (int j = 0; j < u.c; j++)
          ret.mat[i][j] =
              ((ret.mat[i][j] + mat[i][k] * u.mat[k][j]) % MOD + MOD) % MOD;
      }
    }
    return ret;
  }
};
Matrix pow_M(Matrix tmp, Matrix ret, long long n) {
  while (n) {
    if (n & 1) ret = tmp * ret;
    tmp = tmp * tmp;
    n >>= 1;
  }
  return ret;
}
int main() {
  Matrix A(2, 2), B(2, 2), res;
  long long a, b, n, x;
  scanf("%lld%lld%lld%lld", &a, &b, &n, &x);
  A.mat[0][0] = x;
  A.mat[0][1] = 0;
  A.mat[1][0] = b;
  A.mat[1][1] = 0;
  B.mat[0][0] = a, B.mat[0][1] = 1;
  B.mat[1][0] = 0, B.mat[1][1] = 1;
  res = pow_M(B, A, n);
  printf("%lld\n", res.mat[0][0]);
  return 0;
}
