#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define endl "\n"
vector<int> takeVectorInput(int n){
vector<int>v(n);
for(auto &ele:v)cin>>ele;
// vector<int>v(n+1);
// for(int i=1;i<=n;++i) {
// cin>>v[i];
// }
return v;
}
void solve(){
int n,m;
cin>>n>>m;
auto a=takeVectorInput(n);
auto b=takeVectorInput(m);
set<int>st;
for(auto &ele:b)st.insert(ele);
if(st.size()!=10){
NO;
return;
}
int c1=count(a.begin(),a.end(),0);
int c2=count(a.begin(),a.end(),1);
int c3=count(a.begin(),a.end(),2);
int c4=count(a.begin(),a.end(),3);
if(c1&&c2&&c3&&c4)YES;
else NO;
}
signed main(){
fast
int t;
cin>>t;
while(t--){
solve();
}
}