#include<bits/stdc++.h>
using namespace std;
const int N = 3e5 + 9;
using ll = long long;
void solve() {
int n, m ; cin >> n >> m;
set <int> s1, s2;
for(int i=0; i<n; i++) {
int e; cin >> e;
s1.insert(e);
}
for(int i=0; i<m; i++) {
int e; cin >> e;
s2.insert(e);
}
// for(auto u : s1) cout << u << ' ';
// cout << endl;
// for(auto u : s2) cout << u << ' ';
// cout << endl;
if(binary_search(s1.begin(), s1.end(), 0) && binary_search(s1.begin(), s1.end(), 1) && binary_search(s1.begin(), s1.end(), 2) && binary_search(s1.begin(), s1.end(), 3) && s2.size() == 10) {
cout << "YES" << endl;
}
else{
cout << "NO" << endl;
}
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}