There are multiple test cases in the input file. Each test case starts with three integers S , T and M (1<=S<=100, 1<=T<=2000, 0<=M<=10) , representing the number of schools, the number of teams participating in the preliminary contest, and the minimum number of problems which is required to be solved in order to enter the on-site competition, respectively.
Each of the following S lines consists of three integers Id , P and Q , (1<=Id<=S, 0<=P, Q<=1) , representing the Id of the school, whether this school satisfies condition b), and whether this school satisfies condition c).
The last part of each test case consists of T lines. There are two integers on each of the T lines, Sid and Tot (1<=Sid<=S, 0<=Tot<=10) , meaning that a team from school Sid had solved Tot problems in the preliminary contest.
Two consecutive test cases are separated by a blank line. S = 0, T = 0, M = 0 indicates the end of input and should not be processed by your program.