Scanner sc = new Scanner(System.in);
ArrayList tr = new ArrayList<>();
ArrayList dr = new ArrayList<>();
ArrayList ts = new ArrayList<>();
ArrayList ds = new ArrayList<>();
boolean matched = true;
while(sc.hasNextLine()){
int NumofTestcases = sc.nextInt();
for (int i = 0; i < NumofTestcases; i++) {
int trCount = sc.nextInt();
for (int j = 0; j < trCount; j++) {
tr.add(sc.nextInt());
}
int drCount = sc.nextInt();
for (int j = 0; j < drCount; j++) {
dr.add(sc.nextInt());
}
int tsCount = sc.nextInt();
for (int j = 0; j < tsCount; j++) {
ts.add(sc.nextInt());
}
int dsCount = sc.nextInt();
for (int j = 0; j < dsCount; j++) {
ds.add(sc.nextInt());
}
for (int j = 0; j < ds.size(); j++) {
if (!dr.contains(ds.get(j))) {
matched = false;
}
}
for (int j = 0; j < ts.size(); j++) {
if (!tr.contains(ts.get(j))) {
matched = false;
}
}
if (matched) {
System.out.println("Yes");
} else {
System.out.println("NO");
}
matched = true;
tr.clear();
dr.clear();
ds.clear();
ts.clear();
}
}
}