Chef and Combinatorics

All submissions for this problem are available.
Read problems statements in Mandarin Chinese here
Read problems statements in Russian here
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) = A_{0} + A_{1} * N + A_{2} * N^{2} + A_{3} * 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 A_{0}, A_{1}, A_{2}, A_{3}. 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 ≤ A_{i} ≤ 1000
 Sum of all S for all test cases is not greater than 500. It's guaranteed that at least one A_{i} is nonzero.
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).
Author:  gerald 
Tester:  rustinpiece 
Editorial  http://discuss.codechef.com/problems/GERALD05 
Tags  combinatorics, cook41, dynamicprogramming, gerald, medium 
Date Added:  10122013 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 