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.BufferedReader;
import java.util.regex.Pattern;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amalev
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        static final long p = 1_000_000_000l + 7l;

        long[][] pow(long[][] a, long n) {
            long[][] res = new long[2][2];
            res[0][0] = 1l;
            res[1][1] = 1l;

            long[][] c = new long[2][2];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    c[i][j] = a[i][j];
                }
            }

            while (n > 0) {
                if (n % 2 == 0) {
                    c = mult(c, c);
                    n = n >> 1;
                } else {
                    res = mult(res, c);
                    n--;
                }
            }

            return res;
        }

        long[][] mult(long[][] a, long[][] b) {
            long[][] c = new long[2][2];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 2; j++) {
                    for (int k = 0; k < 2; k++) {
                        c[i][j] += (a[i][k] * b[k][j]) % p;
                    }
                }
            }

            return c;
        }

        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long a = in.nextLong();
            long b = in.nextLong();
            long n = in.nextLong();
            long x = in.nextLong();


            long[][] A = new long[2][2];
            A[0][0] = a;
            A[0][1] = b;
            A[1][1] = 1l;

            long[][] X = new long[2][2];
            X[0][0] = x;
            X[1][0] = 1;

            out.println(mult(pow(A, n), X)[0][0] % p);

        }

    }

    static class FastScanner {
        final BufferedReader input;
        String[] buffer;
        int pos;
        final static Pattern SEPARATOR = Pattern.compile("\\s+");

        public FastScanner(InputStream inputStream) {
            input = new BufferedReader(new InputStreamReader(inputStream));
        }

        private String read() {
            try {
                if (buffer == null || pos >= buffer.length) {
                    buffer = SEPARATOR.split(input.readLine());
                    pos = 0;
                }
                return buffer[pos++];
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        }

        public long nextLong() {
            return Long.parseLong(read());
        }

    }
}

