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.*;
import java.util.*;

public class CF678D {
	static int M = 1000000007;
	static int add(int a, int b) { return (a + b) % M; }
	static int mul(int a, int b) { return (int) ((long) a * b % M); }
	static class Z {
		int a, b;
		int c, d;
		Z(int a, int b, int c, int d) {
			this.a = a; this.b = b; this.c = c; this.d = d;
		}
		void mul_(Z z) {
			int a_ = add(mul(a, z.a), mul(b, z.c));
			int b_ = add(mul(a, z.b), mul(b, z.d));
			int c_ = add(mul(c, z.a), mul(d, z.c));
			int d_ = add(mul(c, z.b), mul(d, z.d));
			a = a_; b = b_; c = c_; d = d_;
		}
		void pow(Z z, long n) {
			if (n == 0) {
				a = 1; b = 0;
				c = 0; d = 1;
				return;
			}
			pow(z, n / 2);
			mul_(this);
			if (n % 2 == 1)
				mul_(z);
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int A = Integer.parseInt(st.nextToken());
		int B = Integer.parseInt(st.nextToken());
		long n = Long.parseLong(st.nextToken());
		int x = Integer.parseInt(st.nextToken());
		Z z = new Z(1, 0, 0, 1);
		z.pow(new Z(A, 0, B, 1), n);
		x = add(mul(x, z.a), z.c);
		System.out.println(x);
	}
}
