// Author: Shawn Das Shachin-->(shawn_das)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define pb push_back
#define mod 1000000007
#define srt(v) sort(v.begin(),v.end())
#define rsrt(v) sort(v.rbegin(),v.rend())
#define OPTIMIZE_IO ios::sync_with_stdio(false); cin.tie(nullptr);
void solve(){
int n, m;
cin >> n >> m;
set<int> unb;
bool hz1=false,hz2=false,h1=false,h2=false,h3=false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if(x==0)hz1=true;
if(x==1)h1=true;
if(x==2)h2=true;
if(x==3)h3=true;
else continue;
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
if(x==0)hz2=true;
unb.insert(x);
}
int sum=0;
for(auto &it: unb)sum+=it;
if (sum==45 && hz1 && hz2 && h1 && h2 && h3) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main() {
OPTIMIZE_IO;
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}