// I AM A MUSLIM
#include "bits/stdc++.h"
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define fast_io std::ios::sync_with_stdio(0);std::cin.tie(0)
#define lli long long int
#define flush fflush(stdout)
#define new_line printf("\n")
#define yn(a, b) printf("%s\n", (a) >= (b) ? "YES":"NO")
#define amodm(a, M) (((a)%M+M)%M)
// #define int lli
using pii = std::pair<int,int>;
const int MOD = 1000000007;
const int mxN = 200100;
signed main() {
int testCases=1;
scanf("%d",&testCases);
for (int TC = 1; TC <= testCases; TC++) {
int n, m;
scanf("%d%d",&n,&m);
int fi[5] = {0}; // 0 1 2 3
int se[10] = {0}; // 0 1 2 3 4 5 6 7 8 9
for (int i = 0; i < n; i++) {
int v;
scanf("%d",&v);
if (v <= 3) fi[v] = 1;
}
for (int i = 0; i < m; i++) {
int v;
scanf("%d",&v);
se[v] = 1;
}
bool ok = 1;
for (int i = 0; i <= 3; i++) {
ok &= fi[i];
}
for (int i = 0; i <= 9; i++) {
ok &= se[i];
}
yn(ok, 1);
}
return 0;
}
/*
*/