#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
void solve(){
int n,m;
cin>>n>>m;
vector<int> a(n),b(m),c(10,0), d(4,0);
for(int i=0; i<n; i++){
cin>>a[i];
if(a[i]<4) d[a[i]]=1;
}
for(int i=0; i<m; i++){
cin>>b[i];
c[b[i]]=1;
}
for(auto it: c){
if(it==0){
cout<<"NO"<<endl;
return;
}
}
for(auto it: d){
if(it==0){
cout<<"NO"<<endl;
return;
}
}
cout<<"YES"<<endl;
}
signed main(){
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
optimize();
ll t;
cin>>t;
for(ll i=1; i<=t; i++){
solve();
}
return 0;
}