The first line of the input gives the number of test cases, T. T test cases follow.
Each test case starts with 3 positive intergers, M, N and K represent the amount of magic powers Mr. Panda had, the number of crystal types on the magic continent and the number of crystal synthesis equations.
Then N lines follows, each of them starts with one 0 or 1 which indicates whehter Mr. Panda could create this type of crystal.
If the $i^{th}$ line starts with 0, which means Mr. Panda couldn’t create crystal type i. Then there is one integer $p_i$ in this line which is the price for each piece of crystal type i.
If the $i^{th}$ line starts with 1, which means Mr. Panda could create crystal type i. Then there are two positive integers $c_i$ and $p_i$ in this line, the first is the amout of magic power cost when creates one piece of crystal type i, and the second is is the price for each piece of crystal type i.
The following K lines each start with two interger $x_i$ and $y_i$ , which means for synthesizing one piece of crystal type $x_i$ , $y_i$ rules should be satisfied. Then there are $y_i$ pair of positive intergers $u_j$ and $v_j$ means for one piece of $x^{th}_{i}$ type cristal, we have to collect $v_i$ piece of crystal type $u_i$. Only when all the rules of $u_i$ and $v_i$ are satisfied, Mr. Panda could synthesize one piece $x^{th}_{i}$ type cristal.