The first line of the input contains an integer T (T <= 10), indicating the number of cases.
Each test case contains two blocks.
The first line of the first block contains two integers, n and m (0 < n, m <= 100), indicating the number of terms of the polynomial and the dimension of
. The next n lines contain m + 1 integers each, C
i, p
i1, ..., p
im, indicating the coefficient and the exponent of x
j of the i-th term.
The first line of the second block contains one integer Q (0 < Q <= 100), indicating the number of queries for the given f(x). Each of the following Q lines contains m integers each, indicating the entry values of
.
Note: All the values in the input are nonnegative integers not exceeding 100.