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.StringTokenizer;


public class Main {
    static final int mod = (int) (1e9 + 7);

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int A = sc.nextInt(), B = sc.nextInt();
        long n = sc.nextLong();
        int x = sc.nextInt();
        int[][] res = matMul(matPow(new int[][]{{A, 1}, {0, 1}}, n), new int[][]{{x}, {B}}, 2, 2, 1);
        out.println(res[0][0]);
        out.flush();
        out.close();
    }

    static int[][] matMul(int[][] A, int[][] B, int p, int q, int r) {
        int[][] C = new int[p][r];
        for (int i = 0; i < p; ++i)
            for (int j = 0; j < r; ++j)
                for (int k = 0; k < q; ++k)
                    C[i][j] = (int) ((C[i][j] + 1l * A[i][k] * B[k][j]) % mod);
        return C;
    }

    static int[][] matPow(int[][] base, long p) {
        int n = base.length;
        int[][] ans = new int[n][n];
        for (int i = 0; i < n; i++)
            ans[i][i] = 1;
        while (p != 0) {
            if ((p & 1) == 1)
                ans = matMul(ans, base, n, n, n);
            base = matMul(base, base, n, n, n);
            p >>= 1l;
        }

        return ans;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream system) {
            br = new BufferedReader(new InputStreamReader(system));
        }

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

        public Long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }

        public int[] nextIntArray(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

    }
}