// Author: Mushfiq R.
#include <bits/stdc++.h>
#define endl "\n"
#define fastIO() (ios_base::sync_with_stdio(false), cin.tie(NULL));
using namespace std;
int main()
{
fastIO();
int t = 1;
cin >> t;
while (t--)
{
int m, n;
cin >> m >> n;
int arr_f[4] = {0};
for (int i = 0; i < m; i++)
{
int x;
cin >> x;
if (x < 4)
{
arr_f[x] = 1;
}
}
int arr_s[n] = {0};
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
arr_s[x] = 1;
}
int suma = accumulate(arr_f, arr_f + 3, 0);
int sumb = accumulate(arr_s, arr_s + n, 0);
cout << (suma == 3 && sumb == 10 ? "YES" : "NO") << endl;
}
return 0;
}