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;
template <class T>
void show(const vector<T> &a) {
  for (T x : a) cout << x << " ";
  cout << '\n';
}
vector<long long> xx = {1, 0, -1, 0};
vector<long long> yy = {0, 1, 0, -1};
string dir = "LRUD";
const long long N = 2e5 + 50, oo = 3e18 + 500;
const long long mod = 1e9 + 7;
const long double eps = 1e-7, PI = 2 * acos(0.0);
long long n, m, k;
long long cnt = 0;
long long lg = 18;
vector<long long> g[N];
vector<long long> rg[N];
vector<long long> visit(N, 0);
vector<vector<long long> > mult(vector<vector<long long> > A,
                                vector<vector<long long> > B) {
  vector<vector<long long> > C(2, vector<long long>(2));
  for (long long i = 0; i < 2; i++) {
    for (long long j = 0; j < 2; j++) {
      for (long long z = 0; z < 2; z++) {
        C[i][j] += A[i][z] * B[z][j] % mod;
        C[i][j] %= mod;
      }
    }
  }
  return C;
}
vector<vector<long long> > bin_pow(long long a, long long b, long long n) {
  vector<vector<long long> > A = {{a, b}, {0, 1}};
  vector<vector<long long> > res = {{1, 0}, {0, 1}};
  while (n) {
    if (n & 1) {
      res = mult(res, A);
    }
    A = mult(A, A);
    n >>= 1;
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long A, B, n, x;
  cin >> A >> B >> n >> x;
  vector<vector<long long> > res = bin_pow(A, B, n);
  cnt = (res[0][0] * x % mod + res[0][1]) % mod;
  cout << cnt;
}
