St Andrews Online Judge

Tricky Tribonacci

By Kay Akashi

Time: 1000 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

Sequence aa meets the following recursion: an+3=pan+2+qan+1+rana_{n + 3} = pa_{n + 2} + qa_{n + 1} + ra_{n}. Provided that a1=x,a2=ya_{1} = x, a_{2} = y, and a3=za_{3} = z, your task is to output the value of aka_{k}. However, because the answer can become astronomically large, you are required to output aka_{k} mod 109+710^{9} + 7. In other word, output the remainder of aka_{k} divided by 109+710^{9} + 7.

Constraints

1p,q,r,x,y,z1051 \leq p, q, r, x, y, z \leq 10^{5}, 1k10121 \leq k \leq 10^{12}.

Input

The first line of input contains three integers, pp, qq, and rr. The second line of input contains three integers, xx, yy, and zz. The third line of input contains one integer, kk.

Output

Output the answer.

Examples

Input

1 4 9
3 2 7
4

Output

42

Explanation

In this case a1=1,a2=4,a3=9a_1 = 1, a_2 = 4, a_3 = 9, so a4=3a3+2a2+7a1=42a_4 = 3a_3 + 2a_2 + 7a_1 = 42.

Input

1 1 1
1 1 1
40

Output

129195424

Input

13238 91313 41471
12374 58241 31231
831487118462

Output

102645325