/**
* author: Binoy Barman
* created: 2025-01-02 20:35:35
**/
#include<bits/stdc++.h>
#ifdef LOCAL
#include "debug/trace.hpp"
#else
#define dbg(...) 42
#define print(...) 42
#endif
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = 1e9;
#define int long long
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Testcase_Handler int tts, tc = 1; cin >> tts; hell: while(tts--)
#define uniq(v) sort(all(v)), v.resize(distance(v.begin(), unique(v.begin(), v.end())))
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {bool first = true;for(auto &x : a) {if(!first) out << ' ';first = false;out << x;}return out;};
namespace Dark_Lord_Binoy {
void preprocess() {}
void setup() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
preprocess();
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
int32_t main() {
Dark_Lord_Binoy::setup();
Testcase_Handler {
int n, m;
cin >> n >> m;
vector<int> a(10), b(10);
for (int i = 0; i < n; i++) {
int x; cin >> x;
a[x] = 1;
}
for (int i = 0; i < m; i++) {
int x; cin >> x;
b[x] = 1;
}
bool ok = true;
for (int i = 0; i < 4; i++) ok &= (a[i] == 1);
for (int i = 0; i < 10; i++) ok &= (b[i] == 1);
cout << (ok ? "YES" : "NO") << nl;
}
print(_Time_);
return 0;
}