Time limit
2s
Memory limit
128 MB
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.
6 7 8 9 10: he likes woman 6 most, then women 7 through 10 in that order.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.
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.
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.