#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nl "\n"
#define ws " "
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MOD 1000000007
typedef vector<ll> vi;
typedef vector<pair<ll, ll>> vii;
int main () {
FASTIO
int t;
cin>>t;
while (t--) {
int n, m;
cin>>n>>m;
set <int> st1, st2;
for (int i = 0; i < n; i++) {
int x;
cin>>x;
st1.insert(x);
}
for (int i = 0; i < m; i++) {
int x;
cin>>x;
st2.insert(x);
}
bool p = true;
for (int i = 0; i <= 3; i++) {
if (st1.find(i) == st1.end()) {
p = false;
break;
}
}
for (int i = 0; i <= 9; i++) {
if (st2.find(i) == st2.end()) {
p = false;
break;
}
}
if (p) {
cout<<"YES\n";
} else {
cout<<"NO\n";
}
}
return 0;
}