// Created on: 2025-01-02 20:40
// Author: Safwan_Ibrahim
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
void solve() {
int n, m; cin >> n >> m;
set<int>a, b;
for (int i = 1; i <= n; i++) {
int x; cin >> x;
a.insert(x);
}
for (int i = 1; i <= m; i++) {
int x; cin >> x;
b.insert(x);
}
for (int i = 0; i <= 3; i++) {
if (a.find(i) == a.end()) {
cout << "NO\n"; return;
}
}
for (int i = 0; i <= 9; i++) {
if (b.find(i) == b.end()) {
cout << "NO\n"; return;
}
}
cout << "YES\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1; cin >> t;
while(t--) solve();
return 0;
}