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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
 
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author JENISH
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DIteratedLinearFunction solver = new DIteratedLinearFunction();
        solver.solve(1, in, out);
        out.close();
    }
 
    static class DIteratedLinearFunction {
        long mod = (long) (1e9 + 7);
    long[][] A;

    public void solve(long testNumber, ScanReader in, PrintWriter out) {
        long a = in.scanLong();
        long b = in.scanLong();
        long n = in.scanLong();
        long x = in.scanLong();
        long f1 = sum(mul(a, x), b);
        if (n == 1) {
            out.println(f1);
            return;
        }

        long mat[][] = new long[3][3];
        mat[0] = new long[]{0, 0, 0};
        mat[1] = new long[]{1, a, 0};
        mat[2] = new long[]{0, 1, 1};

        A = new long[3][3];
        A[0] = new long[]{0, 0, 0};
        A[1] = new long[]{1, a, 0};
        A[2] = new long[]{0, 1, 1};

        power(n - 1, mat);
        long ans = sum(sum(mul(f1, mat[1][1]), mul(b, mat[2][1])), mul(x, mat[0][1]));
        out.println(ans);

    }


    void power(long x, long mat[][]) {
        if (x == 1) return;
        power(x / 2, mat);
        mul(mat, mat);
        if (x % 2 == 1)
            mul(mat, A);
    }


    void mul(long[][] mat, long[][] B) {
        long res[][] = new long[3][3];
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                res[i][j] = 0;
                for (int k = 0; k < 3; k++) {
                    res[i][j] = sum(res[i][j], mul(mat[i][k], B[k][j]));
                }
            }
        }

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                mat[i][j] = res[i][j];
            }
        }
    }


    long mul(long a, long b) {
        return (long) ((a * b * 1l) % mod);
    }

    long sum(long a, long b) {
        return (long) ((a + b + 0l) % mod);
    }
    }
 
    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;
 
        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }
 
        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }
 
        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }
 
        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }
 
        public long scanLong() {
            long I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }
 
    }
}