cho.sh
Notes
Loading...

Arranging a Meeting

Time limit

2s

Memory limit

128 MB

Problem

Tae-hyun joins a meeting with four male friends and five women, for a total of five men and five women. After everyone introduces themselves, they decide to form pairs using the following procedure.

  1. Tae-hyun is student 1, the other men are students 2 through 5, and the women are students 6 through 10.
  2. Each participant writes a complete preference ranking of the five people on the other side. No two people may have the same rank, and all five people must appear. Tae-hyun's true preference list is 6 7 8 9 10: he likes woman 6 most, then women 7 through 10 in that order.
  3. In order from woman 6 to woman 10, each woman looks at her preference list and proposes to the man she likes most among the men who have not rejected her before.
  4. When a man receives a proposal, he accepts it if he currently has no tentative partner. If he already has a tentative partner, he compares the two women using his own preference list, keeps the one he likes more as his tentative partner, and rejects the other.
  5. Processing women 6 through 10 once is one round. In the next round, only the women who were rejected participate again.
  6. The process repeats until every woman has a tentative partner. The final tentative partners become the final pairs.

Every participant gives Tae-hyun the preference list they wrote. While applying the procedure, Tae-hyun wonders whether he can get a woman he truly likes more by writing a different preference list for himself.

Given the preference lists written by students 2 through 10, determine whether Tae-hyun can change only his own written preference list so that, according to his true preference list, his final partner is better than the partner he would get by writing the truth.

Input

The first line contains the number of test cases T. (1 <= T <= 20)

Each test case consists of 9 lines. The first four lines are the preference lists of men 2, 3, 4, and 5, in that order. The next five lines are the preference lists of women 6, 7, 8, 9, and 10, in that order.

Tae-hyun's true preference list is always 6 7 8 9 10, and it is not given in the input.

Output

For each test case, print one line. Print YES if Tae-hyun can end up with a woman he truly likes more, and print NO otherwise.