Polynomials

All submissions for this problem are available.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Given n functions y_{i}(x) = a_{0} + a_{1}x + a_{2}x^{2} + a_{3}x^{3} and q queries. For each query, you are given an integer t and you are required to find out y_{i} (i ≤ i ≤ n) that minimizes the value of y_{i}(t).
Input
The first line is an integer T denotes the number of testcases. Each testcase starts with an integer n on a single line, the number of polynomials. The next n lines, each line describes a polynomial contains four integers: a_{0} a_{1} a_{2} a_{3}. Then a line contains q, the number of queries. Each of the next q lines describes a query by a single integer t.
Output
Each query, output the answer on a single line.
Constraints
 1 ≤ T ≤ 10
 1 ≤ n, q ≤ 10^{5}
 0 ≤ t ≤ 10^{5}
 0 ≤ a_{3} ≤ 10^{3}
 0 ≤ a_{i} ≤ 10^{5}
 sum of n, q over all test cases, each is at most 3.10^{5}
Subtasks:
 Subtask #1 (10 points): n, q ≤ 10^{3}
 Subtask #2 (20 points): a_{2} = a_{3} = 0
 Subtask #3 (70 points): original constrains
Example
Input: 1 5 10 5 4 8 2 0 5 0 1 8 0 2 8 7 8 7 7 0 8 1 4 1 3 5 2 Output: 7 47 127 22
Author:  chemthan 
Tags  chemthan, hard, hull, nov17 
Date Added:  27092017 
Time Limit:  2 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, 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, kotlin, PERL6, TEXT, SCM chicken, CLOJ, COB, 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. 