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

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

    static class TaskD {
        public final int mod = 1_000_000_007;

        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int a = in.nextInt();
            int b = in.nextInt();
            long n = in.nextLong();
            int x = in.nextInt();

            long a_n = Functions.bin_pow(a, n, mod);

            long ans = a_n * x;

            ans %= mod;

            if (a == 1)
                ans += b * (n % mod);
            else
                ans += b * (a_n - 1) % mod * Functions.modInverse(a - 1, mod);

            out.println(ans % mod);

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

    }

    static class Functions {
        static long bin_pow(long b, long exp, long mod) {

            long ans = 1;

            for (; exp > 0; exp >>= 1, b %= mod, ans %= mod, b = b * b % mod) {
                if (exp % 2 == 1)
                    ans = ans * b % mod;
            }

            return ans % mod;
        }

        static long modInverse(long b, long mod) {
            return bin_pow(b, mod - 2, mod);
        }

    }
}

