#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tt; cin >> tt;
while (tt--) {
int n, m; cin >> n >> m;
vector<int> a(11, 0), b(11, 0);
int x;
for (int i = 0; i < n; i++) {
cin >> x;
a[x] = 1;
}
for (int i = 0; i < m; i++) {
cin >> x;
b[x] = 1;
}
if (a[0] == 0 || a[1] == 0 || a[2] == 0 || a[3] == 0) cout << "NO\n";
else {
x = 0;
for (int i = 0; i < 10; i++) {
if (b[i] == 0) {
x = 1;
break;
}
}
if (x) cout << "NO\n";
else cout << "YES\n";
}
}
return 0;
}