A sequential value

4

6 votes
Arrays, Number Theory, Data Structures, 1-D, Math, Modulus Arithmetic
Problem

Consider a sequence fn(n0). You do not know the values of fn. However, function F(x) defined as follows:
F(x)=n0fnxn=1+dx+ex21+ax+bx2+cx3

You are given a,b,c,d,e,N. Your task is to calculate fN.

Since this value can be very large, print it modulo 1000000007(109+7). You can read about modular arithmetic here.

You are given T test cases.

Input format

  • The first line contains a single integer T that denotes the number of test cases.
  • For each test case:
    • Six space-separated integers denoting the values of a,b,c,d,e,N.

Output format

For each test case (in a separate line), print the value fN modulo (109+7).

Constraints

1T104109a,b,c,d,e1090N1018

Time Limit: 0.5
Memory Limit: 256
Source Limit:
Explanation

We have T=2.

In the first test case, F(x)=11x=1+x+x2+.., we can see that f5 would correspond to coefficient of x5 which is 1.

In the second test case, F(x)=11+x=1x+x2x3+.., we can see that f1 would correspond to coefficient of x which is 1. However, the modulo value is 1000000006.

Editor Image

?