#include <bits/stdc++.h>
#define pb push_back
#define all(x) x.begin(),x.end();
#define F first
#define S second
#define ll long long
#define int long long
using namespace std;
const int maxn = 1e5 + 5;
int n,m;
signed main(){
int tt = 1;
cin >> tt;
for(int ii = 1; ii <= tt; ii++){
cin >> n >> m;
map <int,bool> mp,mp2;
for(int i = 1; i <= n; i++){
int x;
cin >> x;
mp[x] = 1;
}
for(int i = 1; i <= m; i++){
int x;
cin >> x;
mp2[x] = 1;
}
bool ok = 1;
for(int i = 0; i <= 3; i++){
if(!mp[i]){
ok = 0;
}
}
for(int i = 0; i <= 9; i++){
if(!mp2[i]){
ok = 0;
}
}
if(ok){
cout << "YES\n";
}
else {
cout << "NO\n";
}
}
return 0;
}