#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;
for(auto &it:v){
cin>>it;
st.insert(it);
}
for(auto &it:vv){
cin>>it;
st2.insert(it);
}
sort(vv.begin(),vv.end());
if(st.size() >= 4){
if(st2.size() == 9){
if(vv[0] != 0){
cout<<"NO\n";
}
else{
cout<<"YES\n";
}
}
else if(st2.size() == 10){
cout<<"YES\n";
}
else{
cout<<"NO\n";
}
}
else{
cout<<"NO\n";
}
}
return 0;
}