// 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> una, unb;
bool hz=false;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if(x==0)hz=true;
una.insert(x);
}
for (int i = 0; i < m; i++) {
int x;
cin >> x;
if(x==0)hz=true;
unb.insert(x);
}
int sum1=0,sum2=0;
for(auto &it: una)sum1+=it;
for(auto &it: unb)sum2+=it;
// bool possible = true;
// for (int i = 1; i <= 31; i++) {
// int f = i / 10;
// int s = i % 10;
// if ((una.find(f) != una.end() && unb.find(s) != unb.end()) ||
// (unb.find(f) != unb.end() && una.find(s) != una.end())) {
// continue;
// } else {
// possible = false;
// break;
// }
// }
if (sum1==45 && sum2==45 && hz) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
int main() {
OPTIMIZE_IO;
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}