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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class D {
	
	static int mod = 1000000007;

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] in = br.readLine().split(" ");
		
		int a = Integer.parseInt(in[0]);
		int b = Integer.parseInt(in[1]);
		long n = Long.parseLong(in[2]);
		int x = Integer.parseInt(in[3]);
		
		long[][] M = {{a, b}, {0,1}};
		long[][] X = {{x}, {1}};
		
		long[][] R = multiply(power(M, n), X);
		
		System.out.println(R[0][0]);
	}
	
	public static long[][] multiply(long[][] A, long[][] B){
		int m = A.length;
		int n = A[0].length;
		int p = B[0].length;

		long[][] C = new long[m][p];

		for(int i=0; i<m; i++) {
			for(int j=0; j<p; j++) {
				long current = 0;
				for(int k=0; k<n; k++) {
					current = (current + (A[i][k]*B[k][j]) % mod) % mod;
				}
				C[i][j] = current;
			}
		}

		return C;
	}
	
	public static long[][] power(long[][] M, long n){
		if(n == 1) {
			return M;
		}
		
		long[][] T = power(M, n/2);
		
		if(n%2 == 0) {
			return multiply(T, T);
		}else {
			return multiply(M, multiply(T, T));
		}	
	}
}
