Is Date Possible?

Is Date Possible?

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Time Limit: 1.0 s

Memory Limit: 256.0 MB

Description

Imti has two lists, each containing single-digit numbers. He wants to know if it’s possible to create all the dates from 01 to 31 using these two lists. Here's how he forms a date:

He picks one digit from the first list.
He picks one digit from the second list.
He combines the two digits (first digit followed by the second digit) to form a two-digit number.

For example:
If the first list is [0, 1, 2] and the second list is [1, 2, 3], Imti can form dates like 01, 12, and 23.

However, he cannot form a date like 04 because 4 is not in either list.

Can Imti use the digits in these two lists to form all dates from 01 to 31?

Input

The first line T, (1<=T <=1000)- number of test case.

In each test case contains following line:

The first line contains two integers, 𝑁 and 𝑀 ( 1 ≀ 𝑁 , 𝑀 ≀ \(10^5\) ) representing the sizes of the two lists.

The second line contains 𝑁 integers, the elements of the first list 𝑋 ( 0 ≀ 𝑋 ≀ 9 )

The second line contains 𝑀 integers, the elements of the first list π‘Œ ( 0 ≀ π‘Œ ≀ 9 )

Sum of N over all test cases doesn't exceed \(10^5\).
Sum of M over all test cases doesn't exceed \(10^5\).

Output

In each test case, print "YES" if it's possible to form all dates from 01 to 31, otherwise print "NO".

Sample

Input Output

5
5 10
9 3 5 1 4
4 4 9 6 0 3 6 8 4 0
4 2
3 0 4 1
7 9
11 4
7 8 0 6 4 8 9 9 8 8 5
9 0 6 5
20 10
4 6 4 5 1 8 0 7 3 9 5 5 8 9 2 4 5 8 4 3
7 3 2 4 9 5 8 0 1 6
20 7
4 8 5 2 1 8 9 7 1 5 6 1 6 0 4 6 1 4 1 9
2 9 9 7 2 9 1

NO
NO
NO
YES
NO

Happy New Year 2025

Not Attended
Status
Done
Rule
ACM/ICPC
Problem
8
Start at
2025-01-02 14:30
End at
2025-01-02 17:00
Duration
2.5 hour(s)
Host
Partic.
117