Hong, a private detective, is organizing the information about a murder case he is working on. From the movements of the people connected to the case he wrote down n statements S1,S2,…,Sn. He does not yet know whether each statement is true, so he calls every statement an incident variable. The six statements below are an example.
Hong examined the truth of each incident variable and the relations between the variables, and built a deduction from the result. A deduction is one or more assertions, and every assertion has one of three types. Type 1 says that an incident variable Si is true. Type 2 says that a set of one or more incident variables contains at least one false variable. Type 3 says that Si is true whenever the variables written with it are all true. The three types are written like this.
Suppose Hong's deduction is the following eight assertions.
Assertions 1 and 2 have Type 1, assertion 3 has Type 2, and assertions 4 to 8 have Type 3. The deduction is valid when the assertions do not contradict each other and no Type 3 assertion has every variable on the left of → true while the variable on its right must be false. If some variable on the left of → is false, the truth of the variable on the right does not break the deduction.
A valid assignment is an assignment of true and false to the incident variables that makes the deduction valid. Hong wants to know whether his deduction has a valid assignment.
In the example above, assertions 1 and 2 make S1 and S2 true, and assertion 4 then makes S6 true. Assertion 3 requires one of S1, S2, S6 to be false, so this deduction is not valid. Once assertion 3 is dropped, a valid assignment exists. Setting every variable to true works, and so does setting only S4 to false.
Given Hong's deduction over n incident variables, write a program that decides whether a valid assignment exists.
Your program reads from standard input. The first line has the number of test cases T. Each test case starts with a line of four integers n, m1, m2, m3 (1≤n≤1500, 1≤m1<n, 0≤m2,m3≤1500), where n is the number of incident variables and m1, m2, m3 are the numbers of Type 1, Type 2 and Type 3 assertions.
Each of the next m1 lines has one integer i (1≤i≤n) for the Type 1 assertion Si.
Each of the next m2 lines has k+1 integers k,i1,i2,…,ik (1≤k, 1≤i1,i2,…,ik≤n, and ir=is for r=s) for the Type 2 assertion Si1,Si2,…,Sik→∅.
Each of the next m3 lines has k+2 integers k,j1,j2,…,jk,i (1≤k≤n−1, 1≤j1,j2,…,jk,i≤n, jr=js for r=s, and i=jr for every r) for the Type 3 assertion Sj1,Sj2,…,Sjk→Si.
Your program writes to standard output. Print exactly one line for each test case. Print YES if the deduction is valid, and NO otherwise.