#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main(){
ios :: sync_with_stdio(false);
cin.tie(0);
int tc;
cin>>tc;
while(tc--){
int n,m;
cin>>n>>m;
vector<int>v(n),vv(m);
set<int>st,st2;
int a,b,c,d;
for(auto &it:v){
cin>>it;
st.insert(it);
if(it == 0) a = 1;
if(it == 1) b = 1;
if(it == 2) c = 1;
if(it == 3) d = 1;
}
for(auto &it:vv){
cin>>it;
st2.insert(it);
}
if(a+b+c+d == 4){
if(st2.size() == 10){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
else{
cout<<"NO\n";
}
}
return 0;
}