St Andrews Online Judge

Simple Recursion

By Kay Akashi

Time: 2000 ms
Memory: 256000 kB

The code judging system is only available during contests. Check out the github repo for test cases and solutions.

Please log in.

Problem Statement

Given a recursion rule an+1=pan+qa_{n + 1} = pa_n + q, where a1=1a_1 = 1, output the value of aXa_X mod (109+7)(10^9 + 7) given XX.

Constraints

1p,q30001 \leq p, q \leq 3000.

Subtask 1 (25%)

1X1051 \leq X \leq 10^5.

Subtask 2 (75%)

1X10121 \leq X \leq 10^{12}.

Input

The first line of input contains 22 integers, pp and qq. The second line of input contains 11 integer, XX.

Output

Output a single integer, the value of aXa_X mod (109+7)(10^9 + 7).

Examples

Input

3 4
5

Output

241

Explanation

a1=1a_1 = 1, a2=3×1+4=7a_2 = 3 × 1 + 4 = 7, a3=3×7+4=25a_3 = 3 × 7 + 4 = 25, a4=3×25+4=79a_4 = 3 × 25 + 4 = 79, and a5=3×79+4=241a_5 = 3 × 79 + 4 = 241.

Input

2915 2999
965736817718

Output

56311101