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>
#pragma warning(disable : 4996)
using namespace std;
int IT_MAX = 1 << 21;
const int MOD = 1000000007;
const int INF = 1034567891;
const long long LL_INF = 1234567890123456789ll;
const double PI = 3.141592653589793238;
const long double ERR = 1E-12;
const long long mod = 1e9 + 7;
long long qpow(long long x, long long y) {
  if (y == 0) return 1;
  long long tmp = qpow(x, y / 2);
  if (y & 1) return tmp * tmp % mod * x % mod;
  return tmp * tmp % mod;
}
int ta, tb, tc, td, te;
const int maxnode = 4;
struct Matrix {
  int n;
  long long maze[maxnode][maxnode];
  void init(int n) {
    this->n = n;
    memset(maze, 0, sizeof(maze));
  }
  Matrix operator*(Matrix &rhs) {
    Matrix m;
    m.init(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++)
        for (int k = 0; k < n; k++)
          m.maze[i][j] = (m.maze[i][j] + maze[i][k] * rhs.maze[k][j]) % mod;
    return m;
  }
};
Matrix qpow(Matrix a, long long n) {
  Matrix ans;
  ans.init(a.n);
  for (int i = 0; i < ans.n; i++) ans.maze[i][i] = 1;
  while (n) {
    if (n & 1) ans = ans * a;
    a = a * a;
    n >>= 1;
  }
  return ans;
}
int main() {
  long long a, b, c, d;
  cin >> a >> b >> d >> c;
  Matrix ma;
  ma.init(2);
  ma.maze[0][0] = a;
  ma.maze[0][1] = 0;
  ma.maze[1][0] = 1;
  ma.maze[1][1] = 1;
  ma = qpow(ma, d);
  cout << (ma.maze[0][0] * c + ma.maze[1][0] * b) % mod << endl;
}
