The input consists of multiple test cases. The first line of input contains an integer T, which is the number of test cases.
Each test case is on several lines. The first line contains an integer, N, indicating the quantity of known elements.
Each of the following n lines is consisting of a element description, start with a element name and followed by the weight
W (floating point number), separated by a space.
The (n+1)-th line consists an integer M, indicating the quantity of formulas.
Each of the following M lines is consisting of a formula.
[Technical Specification]
1.T is an integer, and T <=10.
2.N is an integer, and 1 <= N <= 200.
3.W is a floating point number with two fractional digits, and 1 <= W <= 400.
4.M is an integer, and 1 <= M <= 100.
5.Numbers in the formula is always in the range of [2,9] inclusive.
6.The formula?s length does not exceed 500.
7.There's no blank line between two test cases.