9052 - Polynomial Evaluation   

Description


測資有誤暫時請不要嘗試!!!!

There are many ways to calculate a value of a polynomial. One of them is Horner’s rule:


Given a polynomial and some parameters x, compute P(x) by Horner’s rule.

Input

First line contains a positive integer t(t<=1000), which indicates the number of test cases in the input. In each case, the first line gives an integer n(1 <= n <= 1000). The second line contains n+1 integers, which are the coefficients of P(x) arranged from the highest power term to the constant term. The third line gives an integer m (1 <= m <= 105), which is the number of parameters. In next m lines, each line contains an integer, which indicate the parameter x (-300000 <= x <= 300000).

Output

For each case, output the case number like “Case 1:” in a line, each value of m parameters is output in a line and mod 10000007. Please refer to sample output.

Sample Input  Download

Sample Output  Download

Tags




Discuss