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
/*-
 * Codeforces problem :
 * http://codeforces.com/problemset/problem/678/D
 *
 * Print the only integer s — the value g(n)(x) modulo 10^9 + 7.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

/**
 * @author Karthik Venkataraman
 * @email kafy83@gmail.com
 */
public class IteratedLinearFunction {

    class Arithmetic {

        private static final long MOD = (long) 1e9 + 7;

        private long add(long a, long b) {
            return ((a % MOD) + (b % MOD)) % MOD;
        }

        private long sub(long a, long b) {
            return (((a % MOD) - (b % MOD)) + MOD) % MOD;
        }

        private long mul(long a, long b) {
            return ((a % MOD) * (b % MOD)) % MOD;
        }

        private long div(long a, long b) {
            return mul(a, pow(b, MOD - 2));
        }

        private long pow(long a, long b) {
            long result = 1;
            for (; b > 0; b >>= 1) {
                if (b % 2 == 1) {
                    result = mul(result, a);
                }
                a = mul(a, a);
            }
            return result;
        }
    }

    private void compute() {
        InputReader sc = new InputReader(System.in);
        long a = sc.nextLong(), b = sc.nextLong(), n = sc.nextLong(), x = sc.nextLong();
        Arithmetic c = new Arithmetic();
        //a^n*x+b*(1-a^n)/(1-a);
        long apown = c.pow(a, n);
        long term1 = c.mul(apown, x);
        long term2 = a == 1 ? n : c.div(c.sub(1, apown), c.sub(1, a));
        System.out.print(c.add(term1, c.mul(term2, b)));
    }

    class InputReader {

        private static final int INPUT_KB = 1024;
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), INPUT_KB);
        }

        String readNext() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException ex) {
                    throw new IllegalArgumentException(ex);
                }
            }
            return tokenizer.nextToken();
        }

        long nextLong() {
            return Long.parseLong(readNext());
        }
    }

    public static void main(String... args) {
        IteratedLinearFunction ilf = new IteratedLinearFunction();
        ilf.compute();
    }
}