Deduction

No attempts yetTime limit1sMemory limit256 MB

Problem

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 nn statements S1,S2,,SnS_1, S_2, \dots, S_n. 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.

  1. S1S_1: Cheolsu Kim keeps a dog.
  2. S2S_2: Sucheol Park likes cats.
  3. S3S_3: Heeyoung Ahn likes Sucheol Park.
  4. S4S_4: (omitted)
  5. S5S_5: (omitted)
  6. S6S_6: (omitted)

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 SiS_i is true. Type 2 says that a set of one or more incident variables contains at least one false variable. Type 3 says that SiS_i is true whenever the variables written with it are all true. The three types are written like this.

  1. Type 1: SiS_i (SiS_i is true.)
  2. Type 2: Si1,Si2,,SikS_{i_1}, S_{i_2}, \dots, S_{i_k} \to \emptyset (At least one of Si1,Si2,,SikS_{i_1}, S_{i_2}, \dots, S_{i_k} is false.)
  3. Type 3: Sj1,Sj2,,SjkSiS_{j_1}, S_{j_2}, \dots, S_{j_k} \to S_i (If Sj1,Sj2,,SjkS_{j_1}, S_{j_2}, \dots, S_{j_k} are all true, then SiS_i is also true.)

Suppose Hong's deduction is the following eight assertions.

  1. S1S_1
  2. S2S_2
  3. S1,S2,S6S_1, S_2, S_6 \to \emptyset
  4. S1S6S_1 \to S_6
  5. S2S6S_2 \to S_6
  6. S1,S6S3S_1, S_6 \to S_3
  7. S2,S4S1S_2, S_4 \to S_1
  8. S5,S6S2S_5, S_6 \to S_2

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 \to true while the variable on its right must be false. If some variable on the left of \to 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 S1S_1 and S2S_2 true, and assertion 4 then makes S6S_6 true. Assertion 3 requires one of S1S_1, S2S_2, S6S_6 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 S4S_4 to false.

Given Hong's deduction over nn incident variables, write a program that decides whether a valid assignment exists.

Input

Your program reads from standard input. The first line has the number of test cases TT. Each test case starts with a line of four integers nn, m1m_1, m2m_2, m3m_3 (1n15001 \le n \le 1500, 1m1<n1 \le m_1 < n, 0m2,m315000 \le m_2, m_3 \le 1500), where nn is the number of incident variables and m1m_1, m2m_2, m3m_3 are the numbers of Type 1, Type 2 and Type 3 assertions.

Each of the next m1m_1 lines has one integer ii (1in1 \le i \le n) for the Type 1 assertion SiS_i.

Each of the next m2m_2 lines has k+1k+1 integers k,i1,i2,,ikk, i_1, i_2, \dots, i_k (1k1 \le k, 1i1,i2,,ikn1 \le i_1, i_2, \dots, i_k \le n, and irisi_r \ne i_s for rsr \ne s) for the Type 2 assertion Si1,Si2,,SikS_{i_1}, S_{i_2}, \dots, S_{i_k} \to \emptyset.

Each of the next m3m_3 lines has k+2k+2 integers k,j1,j2,,jk,ik, j_1, j_2, \dots, j_k, i (1kn11 \le k \le n-1, 1j1,j2,,jk,in1 \le j_1, j_2, \dots, j_k, i \le n, jrjsj_r \ne j_s for rsr \ne s, and ijri \ne j_r for every rr) for the Type 3 assertion Sj1,Sj2,,SjkSiS_{j_1}, S_{j_2}, \dots, S_{j_k} \to S_i.

Output

Your program writes to standard output. Print exactly one line for each test case. Print YES if the deduction is valid, and NO otherwise.