P13445 [CodeChef] gerald05
普及
题目描述

Problem Statement
Chef studies combinatorics. He tries to group objects by their rang (a positive integer associated with each object). He also gives the formula for calculating the number of different objects with rang N as following:
the number of different objects with rang N = F(N) = A0 + A1 * N + A2 * N^2 + A3 * N^3.
Now Chef wants to know how many different multisets of these objects exist such that sum of rangs of the objects in the multiset equals to S. You are given the coefficients in F(N) and the target sum S. Please, find the number of different multisets modulo 1,000,000,007.
You should consider a multiset as an unordered sequence of integers. Two multisets are different if and only if there at least exists one element which occurs X times in the first multiset but Y times in the second one, where (X ≠ Y).

Input
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains four integers A0, A1, A2, A3. The second line contains an integer S.

Output
For each test case, output a single line containing a single integer - the answer to the test case modulo 1,000,000,007.

Constraints

1 ≤ T ≤ 500
1 ≤ S ≤ 100
0 ≤ Ai ≤ 1000
Sum of all S for all test cases is not greater than 500. It's guaranteed that at least one Ai is non-zero.

Example
Input:
4
1 0 0 0
1
1 0 0 0
3
0 1 0 0
2
2 3 1 4
10

Output:
1
3
3
213986343

Explanation
Example case 2.
In the second example function looks as follows F(N) = 1. So for each rang there is a single object of the rang. To get multiset with sum of rangs equal to 3, you can pick: three objects of rang 1, or one object of rang 1 and one of rang 2, or only one object of rang 3.
Example case 3.
In the third example function looks as follows F(N) = N. So, you have one distinct object of rang 1, two distinct objects of rang 2, three distinct objects of rang 3 and so on. To get
multiset with sum of rangs equal to 2, you can pick: two objects of rang 1, one of objects of rang 2 (two ways).

输入格式

见题面

输出格式

见题面

样例输入
4 1 0 0 0 1 1 0 0 0 3 0 1 0 0 2 2 3 1 4 10
样例输出
1 3 3 213986343