Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types:
- Truth task: Ram has to truthfully answer a question.
- Dare task: Ram has to perform a given task.
Each task is described by an integer. (If a truth task and a dare task are described by the same integer, they are still different tasks.) You are given four lists of tasks:
- $T_{r, 1}, T_{r, 2}, \dots, T_{r, t_r}$: the truth tasks Ram can perform.
- $D_{r, 1}, D_{r, 2}, \dots, D_{r, d_r}$: the dare tasks Ram can perform.
- $T_{s, 1}, T_{s, 2}, \dots, T_{s, t_s}$: the truth tasks Shyam can ask Ram to perform.
- $D_{s, 1}, D_{s, 2}, \dots, D_{s, d_s}$: the dare tasks Shyam can ask Ram to perform.
Note that the elements of these lists are not necessarily distinct, each task may be repeated any number of times in each list.
Shyam wins the game if he can find a task Ram cannot perform. Ram wins if he performs all tasks Shyam asks him to. Find the winner of the game.
Let's take an example where Ram can perform truth tasks $3$, $2$ and $5$ and dare tasks $2$ and $100$, and Shyam can give him truth tasks $2$ and $3$ and a dare task $100$. We can see that whichever truth or dare tasks Shyam asks Ram to perform, Ram can easily perform them, so he wins. However, if Shyam can give him dare tasks $3$ and $100$, then Ram will not be able to perform dare task $3$, so Shyam wins.

-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $t_r$.
- The second line contains $t_r$ space-separated integers $T_{r, 1}, T_{r, 2}, \dots, T_{r, t_r}$.
- The third line contains a single integer $d_r$.
- The fourth line contains $d_r$ space-separated integers $D_{r, 1}, D_{r, 2}, \dots, D_{r, d_r}$.
- The fifth line contains a single integer $t_s$.
- The sixth line contains $t_s$ space-separated integers $T_{s, 1}, T_{s, 2}, \dots, T_{s, t_s}$.
- The seventh line contains a single integer $d_s$.
- The eighth line contains $d_s$ space-separated integers $D_{s, 1}, D_{s, 2}, \dots, D_{s, d_s}$.

-----Output-----
For each test case, print a single line containing the string "yes" if Ram wins the game or "no" otherwise.

-----Constraints-----
- $1 \le T \le 100$
- $1 \le t_r, d_r, t_s, d_s \le 100$
- $1 \le T_{r, i} \le 100$ for each valid $i$
- $1 \le D_{r, i} \le 100$ for each valid $i$
- $1 \le T_{s, i} \le 100$ for each valid $i$
- $1 \le D_{s, i} \le 100$ for each valid $i$

-----Example Input-----
4
2
1 2
3
1 3 2
1
2
2
3 2
2
1 2
3
1 3 2
1
2
3
3 2 4
3
3 2 5
2
2 100
1
2
1
100
2
1 2
3
1 3 2
1
2
3
3 2 2

-----Example Output-----
yes
no
yes
yes

-----Explanation-----
Example case 1: Ram's truth tasks are $[1, 2]$ and his dare tasks are $[1, 3, 2]$. Shyam's truth tasks are $[2]$ and his dare tasks are $[3, 2]$. Ram can perform all tasks Shyam gives him.
Example case 2: Ram's truth tasks are $[1, 2]$ and his dare tasks are $[1, 3, 2]$. Shyam's truth tasks are $[2]$ and his dare tasks are $[3, 2, 4]$. If Shyam asks Ram to perform dare task $4$, Ram will not be able to do it.

Source: codechef | Difficulty: EASY
Tags: Data structures

Implementation


Solutions:
t = int(input())
for k in range(t):
	tr = int(input())
	tr1 = list(map(int, input().strip().split()))
	dr = int(input())
	dr1 = list(map(int, input().strip().split()))
	ts = int(input())
	ts1 = list(map(int, input().strip().split()))
	ds = int(input())
	ds1 = list(map(int, input().strip().split()))
	flag = 1
	for x in ts1:
		if x not in tr1:
			flag = 0
	for y in ds1:
		if y not in dr1:
			flag = 0
	if flag == 1:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	a = int(input())
	la = list(map(int, input().split()))
	b = int(input())
	lb = list(map(int, input().split()))
	c = int(input())
	lc = list(map(int, input().split()))
	d = int(input())
	ld = list(map(int, input().split()))
	flag1 = 0
	flag2 = 0
	for i in lc:
		if i in la:
			flag1 = 1
		else:
			flag1 = 0
			break
	for i in ld:
		if i in lb:
			flag2 = 1
		else:
			flag2 = 0
			break
	if flag1 == 1 and flag2 == 1:
		print('yes')
	else:
		print('no')


T = int(input())
for i in range(T):
	tr = int(input())
	trs = list(map(int, input().split()))
	dr = int(input())
	drs = list(map(int, input().split()))
	ts = int(input())
	tss = list(map(int, input().split()))
	ds = int(input())
	dss = list(map(int, input().split()))
	flag = 0
	for a in tss:
		if a not in trs:
			flag = 1
	for b in dss:
		if b not in drs:
			flag = 1
	if flag == 0:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	a = int(input())
	p = set(list(map(int, input().split())))
	b = int(input())
	q = set(list(map(int, input().split())))
	c = int(input())
	r = set(list(map(int, input().split())))
	d = int(input())
	s = set(list(map(int, input().split())))
	if r.issubset(p) and s.issubset(q):
		print('yes')
	else:
		print('no')


class Solution:

	def truth_dare(self, tr_list, dr_list, ts_list, ds_list):
		for i in ts_list:
			if i not in tr_list:
				return 'no'
		for i in ds_list:
			if i not in dr_list:
				return 'no'
		return 'yes'
t = int(input())
for _ in range(t):
	tr = int(input())
	tr_list = [int(x) for x in input().split()]
	dr = int(input())
	dr_list = [int(x) for x in input().split()]
	ts = int(input())
	ts_list = [int(x) for x in input().split()]
	ds = int(input())
	ds_list = [int(x) for x in input().split()]
	chef = Solution()
	print(chef.truth_dare(tr_list, dr_list, ts_list, ds_list))


for _ in range(int(input())):
	tn1 = int(input())
	tr = list(map(int, input().split()))
	dn1 = int(input())
	dr = list(map(int, input().split()))
	tn2 = int(input())
	ts = list(map(int, input().split()))
	dn2 = int(input())
	ds = list(map(int, input().split()))
	f = 'yes'
	for i in ts:
		if i not in tr:
			f = 'no'
			break
	for i in ds:
		if i not in dr:
			f = 'no'
			break
	print(f)


for _ in range(int(input())):
	(N1, T1) = (int(input()), list(map(int, input().split())))
	(N2, D1) = (int(input()), list(map(int, input().split())))
	(c, d) = (0, 0)
	(N3, T2) = (int(input()), list(map(int, input().split())))
	(N4, D2) = (int(input()), list(map(int, input().split())))
	for val in T2:
		if val in T1:
			c += 1
	for val in D2:
		if val in D1:
			d += 1
	print('yes' if c == len(T2) and d == len(D2) else 'no')


for _ in range(int(input())):
	tr = int(input())
	trl = list(map(int, input().split()))
	dr = int(input())
	drl = list(map(int, input().split()))
	ts = int(input())
	tsl = list(map(int, input().split()))
	ds = int(input())
	dsl = list(map(int, input().split()))
	(c, c1) = (0, 0)
	for i in tsl:
		if i in trl:
			c += 1
	for i in dsl:
		if i in drl:
			c1 += 1
	if c == ts and c1 == ds:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	n1 = int(input())
	tr = list(map(int, input().split()))
	n2 = int(input())
	dr = list(map(int, input().split()))
	n3 = int(input())
	ts = list(map(int, input().split()))
	n4 = int(input())
	ds = list(map(int, input().split()))
	temp = 0
	for i in ts:
		if i not in tr:
			temp = 1
			break
	for i in ds:
		if i not in dr:
			temp = 2
			break
	if temp == 0:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	trarr = set([int(x) for x in input().split()])
	dr = int(input())
	drarr = set([int(x) for x in input().split()])
	ts = int(input())
	tsarr = [int(x) for x in input().split()]
	ds = int(input())
	dsarr = [int(x) for x in input().split()]
	ans = 'yes'
	for i in tsarr:
		if not i in trarr:
			ans = 'no'
			break
	for i in dsarr:
		if not i in drarr:
			ans = 'no'
			break
	print(ans)


for _ in range(int(input())):
	t1 = int(input())
	ta1 = list(map(int, input().split()))
	d1 = int(input())
	da1 = list(map(int, input().split()))
	t2 = int(input())
	ta2 = list(map(int, input().split()))
	d2 = int(input())
	da2 = list(map(int, input().split()))
	if set(ta2).issubset(set(ta1)) and set(da2).issubset(set(da1)):
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	a1 = int(input())
	a = list(map(int, input().split()))
	b1 = int(input())
	b = list(map(int, input().split()))
	s1 = int(input())
	s = list(map(int, input().split()))
	s2 = int(input())
	ss = list(map(int, input().split()))
	c = 0
	d = 0
	for i in s:
		if i not in a:
			c = 1
	for i in ss:
		if i not in b:
			d = 1
	if c == 1 or d == 1:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	rt = int(input())
	rtl = list(map(int, input().split()))
	rd = int(input())
	rdl = list(map(int, input().split()))
	st = int(input())
	stl = list(map(int, input().split()))
	sd = int(input())
	sdl = list(map(int, input().split()))
	check1 = True
	for i in stl:
		if i in rtl:
			pass
		else:
			check1 = False
			break
	check2 = True
	for i in sdl:
		if i in rdl:
			pass
		else:
			check2 = False
			break
	if check1 == True and check2 == True:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	Tr = list(map(int, input().split()))
	dr = int(input())
	Dr = list(map(int, input().split()))
	ts = int(input())
	Ts = list(map(int, input().split()))
	ds = int(input())
	Ds = list(map(int, input().split()))
	if all((x in Tr for x in Ts)) and all((y in Dr for y in Ds)):
		print('yes')
	else:
		print('no')


try:
	for _ in range(int(input())):
		(c, d) = (0, 0)
		t1 = int(input())
		r1 = list(map(int, input().split()))
		d1 = int(input())
		r2 = list(map(int, input().split()))
		t2 = int(input())
		r3 = list(map(int, input().split()))
		d2 = int(input())
		r4 = list(map(int, input().split()))
		for i in range(t2):
			a = r3[i]
			if a in r1:
				c = c + 1
		for i in range(d2):
			b = r4[i]
			if b in r2:
				d = d + 1
		if c == len(r3) and d == len(r4):
			print('yes')
		else:
			print('no')
except:
	pass


t = int(input())
for tc in range(t):
	r = int(input())
	rl = list(map(int, input().split()))
	d = int(input())
	dl = list(map(int, input().split()))
	x = int(input())
	xl = list(map(int, input().split()))
	y = int(input())
	yl = list(map(int, input().split()))
	if set(rl) | set(xl) == set(rl) and set(dl) | set(yl) == set(dl):
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	tr = int(input())
	t1 = [int(i) for i in input().split()]
	dr = int(input())
	d1 = [int(i) for i in input().split()]
	ts = int(input())
	t2 = [int(i) for i in input().split()]
	ds = int(input())
	d2 = [int(i) for i in input().split()]
	k = 0
	for i in t2:
		if i not in t1:
			k = 1
			break
	for i in d2:
		if i not in d1:
			k = 1
			break
	if k == 1:
		print('no')
	if k == 0:
		print('yes')


for _ in range(int(input())):
	a = int(input())
	tr = list(map(int, input().split()))
	b = int(input())
	dr = list(map(int, input().split()))
	c = int(input())
	ts = list(map(int, input().split()))
	d = int(input())
	ds = list(map(int, input().split()))
	if all((i in tr for i in ts)) and all((i in dr for i in ds)):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	rt = int(input())
	tr = list(map(int, input().split()))
	rd = int(input())
	dr = list(map(int, input().split()))
	st = int(input())
	ts = list(map(int, input().split()))
	sd = int(input())
	ds = list(map(int, input().split()))
	l = []
	for i in ts:
		if i in tr:
			l.append('y')
		else:
			l.append('no')
	for i in ds:
		if i in dr:
			l.append('y')
		else:
			l.append('no')
	if 'no' in l:
		print('no')
	else:
		print('yes')


t = int(input())
while t != 0:
	count = 0
	count1 = 0
	tr = int(input())
	tlr = set(map(int, input().split()))
	dr = int(input())
	dlr = set(map(int, input().split()))
	ts = int(input())
	tls = set(map(int, input().split()))
	ds = int(input())
	dls = set(map(int, input().split()))
	x = dls.difference(dlr)
	y = tls.difference(tlr)
	if len(x) == 0 and len(y) == 0:
		print('yes')
	else:
		print('no')
	t = t - 1


for _ in range(int(input())):
	t_r = int(input())
	tr = list(map(int, input().split()))
	d_r = int(input())
	dr = list(map(int, input().split()))
	t_s = int(input())
	ts = list(map(int, input().split()))
	d_s = int(input())
	ds = list(map(int, input().split()))
	flag = True
	for t in ts:
		if t not in tr:
			flag = False
			break
	if flag:
		for d in ds:
			if d not in dr:
				flag = False
				break
	print('yes' if flag else 'no')


for _ in range(int(input())):
	tr = int(input())
	trl = list(map(int, input().split()))
	dr = int(input())
	drl = list(map(int, input().split()))
	ts = int(input())
	tsl = list(map(int, input().split()))
	ds = int(input())
	dsl = list(map(int, input().split()))
	for item in tsl:
		if item in trl:
			res = 1
			continue
		else:
			res = 0
			break
	for item1 in dsl:
		if item1 in drl:
			res1 = 1
			continue
		else:
			res1 = 0
			break
	if res == 1 and res1 == 1:
		print('yes')
	else:
		print('no')


n = int(input())
for i in range(n):
	a = int(input())
	l = list(map(int, input().split()))
	b = int(input())
	m = list(map(int, input().split()))
	c = int(input())
	n = list(map(int, input().split()))
	d = int(input())
	o = list(map(int, input().split()))
	k = 0
	for j in n:
		if j in l:
			k = k + 1
	for j in o:
		if j in m:
			k = k + 1
	if k == len(n) + len(o):
		print('yes')
	else:
		print('no')


t = int(input())
while t > 0:
	n = 0
	s = ''
	rset1 = {}
	rset2 = {}
	sset1 = {}
	sset2 = {}
	n = int(input())
	s = input()
	rset1 = set(s.split(' '))
	n = int(input())
	s = input()
	rset2 = set(s.split(' '))
	n = int(input())
	s = input()
	sset1 = set(s.split(' '))
	n = int(input())
	s = input()
	sset2 = set(s.split(' '))
	if sset1.issubset(rset1) and sset2.issubset(rset2):
		print('yes')
	else:
		print('no')
	t -= 1


for _ in range(int(input())):
	t = int(input())
	ram_t = list(map(int, input().strip().split()))
	d = int(input())
	Ram_d = list(map(int, input().strip().split()))
	t1 = int(input())
	shyam_t = list(map(int, input().strip().split()))
	d1 = int(input())
	shyam_d = list(map(int, input().strip().split()))
	f = 0
	for i in shyam_d:
		if i not in Ram_d:
			f = 1
			break
	for i in shyam_t:
		if i not in ram_t:
			f = 1
			break
	if f == 0:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	t1 = int(input())
	r1 = set(map(int, input().split()))
	t2 = int(input())
	r2 = set(map(int, input().split()))
	d1 = int(input())
	s1 = set(map(int, input().split()))
	d2 = int(input())
	s2 = set(map(int, input().split()))
	s1.difference_update(r1)
	s2.difference_update(r2)
	if len(s1) == 0 and len(s2) == 0:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	a = int(input())
	r = list(map(int, input().split()))
	a1 = int(input())
	r1 = list(map(int, input().split()))
	b = int(input())
	s = list(map(int, input().split()))
	b1 = int(input())
	s1 = list(map(int, input().split()))
	p = True
	q = True
	for i in s:
		if i not in r:
			p = False
			break
	for i in s1:
		if i not in r1:
			q = False
			break
	if q and p:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	tr = int(input())
	trr = set(map(int, input().split()))
	dr = int(input())
	drr = set(map(int, input().split()))
	ts = int(input())
	tsr = set(map(int, input().split()))
	ds = int(input())
	dsr = set(map(int, input().split()))
	candare = True
	cantruth = True
	for ele in tsr:
		if ele not in trr:
			cantruth = False
	for ele in dsr:
		if ele not in drr:
			candare = False
	if cantruth and candare:
		print('yes')
	else:
		print('no')


from sys import stdin
input = stdin.readline

def f(tr, dr, ts, ds):
	for i in ts:
		if i not in tr:
			return 'no'
	for i in ds:
		if i not in dr:
			return 'no'
	return 'yes'
for _ in range(int(input())):
	input()
	tr = set(map(int, input().split()))
	input()
	dr = set(map(int, input().split()))
	input()
	ts = set(map(int, input().split()))
	input()
	ds = set(map(int, input().split()))
	print(f(tr, dr, ts, ds))


t = int(input())
for i in range(t):
	truthtasks = []
	daretasks = []
	tr = int(input())
	TR = list(map(int, input().split()))
	dr = int(input())
	DR = list(map(int, input().split()))
	ts = int(input())
	TS = list(map(int, input().split()))
	ds = int(input())
	DS = list(map(int, input().split()))
	for i in TS:
		if i in TR:
			flag = 1
		else:
			flag = 0
			break
	if flag:
		for j in DS:
			if j in DR:
				flag = 1
			else:
				flag = 0
				break
	if flag:
		print('yes')
	else:
		print('no')


t = int(input())
for t in range(t):
	tr = int(input())
	arrtr = set([int(i) for i in input().split()])
	dr = int(input())
	arrdr = set([int(i) for i in input().split()])
	ts = int(input())
	arrts = set([int(i) for i in input().split()])
	ds = int(input())
	arrds = set([int(i) for i in input().split()])
	flag = 1
	for i in arrts:
		if i not in arrtr:
			flag = 0
			break
	if flag == 1:
		for i in arrds:
			if i not in arrdr:
				flag = 0
				break
	if flag == 0:
		print('no')
	else:
		print('yes')


for i in range(int(input())):
	_ = int(input())
	Tr = list(map(int, input().split()))
	_ = int(input())
	Dr = list(map(int, input().split()))
	_ = int(input())
	Ts = list(map(int, input().split()))
	_ = int(input())
	Ds = list(map(int, input().split()))
	for j in Ts:
		if j not in Tr:
			print('no')
			break
	else:
		for k in Ds:
			if k not in Dr:
				print('no')
				break
		else:
			print('yes')


from collections import Counter
t = int(input())
for _ in range(t):
	f = 0
	n1 = int(input())
	Tr = list(map(int, input().split()))
	n2 = int(input())
	Dr = list(map(int, input().split()))
	n3 = int(input())
	Ts = list(map(int, input().split()))
	n4 = int(input())
	Ds = list(map(int, input().split()))
	for i in Ts:
		if i not in Tr:
			f = 1
	for i in Ds:
		if i not in Dr:
			f = 1
	if f == 0:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	trl = [int(x) for x in input().split()]
	dr = int(input())
	drl = [int(x) for x in input().split()]
	ts = int(input())
	tsl = [int(x) for x in input().split()]
	ds = int(input())
	dsl = [int(x) for x in input().split()]
	flag = 1
	for i in tsl:
		if i not in trl:
			flag = 0
			break
	if flag:
		for i in dsl:
			if i not in drl:
				flag = 0
				break
	if flag:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	r1 = list(map(int, input().split()))
	dr = int(input())
	r2 = list(map(int, input().split()))
	ts = int(input())
	s1 = list(map(int, input().split()))
	ds = int(input())
	s2 = list(map(int, input().split()))
	count = 0
	for i in s1:
		if i in r1:
			count += 1
	for i in s2:
		if i in r2:
			count += 1
	if count == len(s1) + len(s2):
		print('yes')
	else:
		print('no')


try:
	for _ in range(int(input())):
		n = int(input())
		d = list(map(int, input().split()))
		s = int(input())
		p = list(map(int, input().split()))
		o = int(input())
		t = list(map(int, input().split()))
		w = int(input())
		q = list(map(int, input().split()))
		l = []
		for i in t:
			if i in d:
				l.append('y')
			else:
				l.append('no')
		for i in q:
			if i in p:
				l.append('y')
			else:
				l.append('no')
		if 'no' in l:
			print('no')
		else:
			print('yes')
except:
	pass


t = int(input())
for i in range(t):
	tr = int(input())
	r_truth = set(map(int, input().split()))
	dr = int(input())
	r_dare = set(map(int, input().split()))
	ts = int(input())
	s_truth = set(map(int, input().split()))
	ds = int(input())
	s_dare = set(map(int, input().split()))
	for task in s_truth:
		if task not in r_truth:
			print('no')
			break
	else:
		for task in s_dare:
			if task not in r_dare:
				print('no')
				break
		else:
			print('yes')


t = int(input())
for i in range(t):
	tr1 = int(input())
	tr = list(map(int, input().split()))
	dr1 = int(input())
	dr = list(map(int, input().split()))
	ts1 = int(input())
	ts = list(map(int, input().split()))
	ds1 = int(input())
	ds = list(map(int, input().split()))
	flag = False
	if all((x in tr for x in ts)) and all((x in dr for x in ds)):
		flag = True
	if flag == True:
		print('yes')
	else:
		print('no')


for t in range(int(input())):
	t1 = int(input())
	tr = input().split()
	d1 = int(input())
	dr = input().split()
	t2 = int(input())
	ts = input().split()
	d2 = int(input())
	ds = input().split()
	val = 0
	for i in ts:
		if i in tr:
			continue
		else:
			val += 1
	for i in ds:
		if i in dr:
			continue
		else:
			val += 1
	if val > 0:
		print('no')
	else:
		print('yes')


for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	c = int(input())
	d = list(map(int, input().split()))
	e = int(input())
	f = list(map(int, input().split()))
	g = int(input())
	h = list(map(int, input().split()))
	print('yes' if set(b) | set(f) == set(b) and set(d) | set(h) == set(d) else 'no')


t = int(input())
for i in range(t):
	tr = input()
	ltr = list(map(int, input().split()))
	dr = input()
	ldr = list(map(int, input().split()))
	ts = input()
	lts = list(map(int, input().split()))
	ds = input()
	lds = list(map(int, input().split()))
	f = 0
	z = 1
	for j in lts:
		if j in ltr:
			continue
		else:
			print('no')
			f = 1
			break
	if f == 0:
		for j in lds:
			if j in ldr:
				continue
			else:
				print('no')
				z = 0
				break
	if z == 1 and f == 0:
		print('yes')


def bs(a, n, k):
	l = 0
	h = n - 1
	while l <= h:
		mid = (l + h) // 2
		if a[mid] == k:
			return 1
		if a[mid] < k:
			l = mid + 1
		else:
			h = mid - 1
	return 0
t = int(input())
for kk in range(t):
	ntr = int(input())
	tr = [int(x) for x in input().split()]
	tr.sort()
	ndr = int(input())
	dr = [int(x) for x in input().split()]
	dr.sort()
	nts = int(input())
	ts = [int(x) for x in input().split()]
	nds = int(input())
	ds = [int(x) for x in input().split()]
	s = 1
	for i in range(nts):
		if bs(tr, ntr, ts[i]):
			continue
		else:
			s = 0
			break
	if s == 0:
		print('no')
		continue
	for i in range(nds):
		if bs(dr, ndr, ds[i]):
			continue
		else:
			s = 0
			break
	if s == 0:
		print('no')
		continue
	if s == 1:
		print('yes')


def main():
	T = int(input())
	for _ in range(T):
		tr = int(input())
		arrtr = list(map(int, input().split(' ')))[:tr]
		dr = int(input())
		arrdr = list(map(int, input().split(' ')))[:dr]
		ts = int(input())
		arrts = list(map(int, input().split(' ')))[:ts]
		ds = int(input())
		arrds = list(map(int, input().split(' ')))[:ds]
		task = True
		dare = True
		for i in range(ts):
			if arrts[i] not in arrtr:
				task = False
				break
		for j in range(ds):
			if arrds[j] not in arrdr:
				dare = False
				break
		print('yes' if task and dare else 'no')
main()


for _ in range(int(input())):
	t_r = int(input())
	tr = list(map(int, input().split()))
	d_r = int(input())
	dr = list(map(int, input().split()))
	t_s = int(input())
	ts = list(map(int, input().split()))
	d_s = int(input())
	ds = list(map(int, input().split()))
	l = []
	for i in ts:
		if i in tr:
			l.append('y')
		else:
			l.append('no')
	for i in ds:
		if i in dr:
			l.append('y')
		else:
			l.append('no')
	if 'no' in l:
		print('no')
	else:
		print('yes')


for i in range(int(input())):
	tr1 = int(input())
	tr = list(map(int, input().split()))
	dr1 = int(input())
	dr = list(map(int, input().split()))
	ts1 = int(input())
	ts = list(map(int, input().split()))
	ds1 = int(input())
	ds = list(map(int, input().split()))
	if set(tr) | set(ts) == set(tr) and set(dr) | set(ds) == set(dr):
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	ntr = int(input())
	ttr = [int(i) for i in input().split()]
	ndr = int(input())
	dtr = [int(i) for i in input().split()]
	nts = int(input())
	tts = [int(i) for i in input().split()]
	nds = int(input())
	dts = [int(i) for i in input().split()]
	c = 0
	for i in tts:
		if i in ttr:
			c += 1
	for i in dts:
		if i in dtr:
			c += 1
	if c == len(tts) + len(dts):
		print('yes')
	else:
		print('no')


t = int(input())
for u in range(t):
	n1 = int(input())
	tr = list(map(int, input().split()))
	n2 = int(input())
	dr = list(map(int, input().split()))
	n3 = int(input())
	ts = list(map(int, input().split()))
	n3 = int(input())
	ds = list(map(int, input().split()))
	win = 0
	for i in ts:
		if i not in tr:
			win = 'no'
			break
	if win:
		print(win)
		continue
	for i in ds:
		if i not in dr:
			win = 'no'
			break
	if win:
		print(win)
		continue
	print('yes')


def Check(ram, shyam):
	for i in shyam:
		if i not in ram:
			return False
	return True
for _ in range(int(input())):
	tR = int(input())
	Tr = list(map(int, input().split()))
	dR = int(input())
	Dr = list(map(int, input().split()))
	tS = int(input())
	Ts = list(map(int, input().split()))
	dS = int(input())
	Ds = list(map(int, input().split()))
	truthCheck = Check(Tr, Ts)
	dareCheck = Check(Dr, Ds)
	if truthCheck and dareCheck:
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	lrt = int(input())
	Rt = list(map(int, input().split()))
	ldt = int(input())
	Dt = list(map(int, input().split()))
	lst = int(input())
	St = list(map(int, input().split()))
	lsdt = int(input())
	sdt = list(map(int, input().split()))
	f1 = 0
	f2 = 0
	for i in St:
		if i not in Rt:
			f1 += 1
	for i in sdt:
		if i not in Dt:
			f2 += 1
	if f1 == 0 and f2 == 0:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	l_tr = int(input())
	tr = list(map(int, input().split()))
	l_dr = int(input())
	dr = list(map(int, input().split()))
	l_ts = int(input())
	ts = list(map(int, input().split()))
	l_ds = int(input())
	ds = list(map(int, input().split()))
	if set(tr) | set(ts) == set(tr) and set(dr) | set(ds) == set(dr):
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	Tr = list(map(int, input().split()))
	dr = int(input())
	Dr = list(map(int, input().split()))
	ts = int(input())
	Ts = list(map(int, input().split()))
	ds = int(input())
	Ds = list(map(int, input().split()))
	for truth_s in Ts:
		if truth_s in Tr:
			flag = 1
		else:
			flag = 0
			break
	if flag:
		for dare_s in Ds:
			if dare_s in Dr:
				flag = 1
			else:
				flag = 0
				break
	if flag:
		print('yes')
	else:
		print('no')


t = int(input())
while t:
	t1 = int(input())
	ramt = list(map(int, input().split()))
	d1 = int(input())
	ramd = list(map(int, input().split()))
	t2 = int(input())
	shyamt = list(map(int, input().split()))
	d2 = int(input())
	shyamd = list(map(int, input().split()))
	f1 = 0
	f2 = 0
	for x in shyamt:
		if x not in ramt:
			f1 = 1
	for y in shyamd:
		if y not in ramd:
			f2 = 1
	if f1 == 1 or f2 == 1:
		print('no')
	else:
		print('yes')
	t = t - 1


for i in range(int(input())):
	tr = int(input())
	a = set(map(int, input().split()))
	dr = int(input())
	b = set(map(int, input().split()))
	ts = int(input())
	c = set(map(int, input().split()))
	ds = int(input())
	d = set(map(int, input().split()))
	if d.issubset(b) and c.issubset(a):
		print('yes')
	else:
		print('no')


tc = int(input())
for _ in range(tc):
	tn_r = int(input())
	tr = list(map(int, input().split()))
	dn_r = int(input())
	dr = list(map(int, input().split()))
	tn_s = int(input())
	ts = list(map(int, input().split()))
	dn_s = int(input())
	ds = list(map(int, input().split()))
	gorb = True
	for i in range(tn_s):
		if ts[i] not in tr:
			gorb = False
	for i in range(dn_s):
		if ds[i] not in dr:
			gorb = False
	print('yes' if gorb else 'no')


import os, sys, io, math
from re import *
from math import *
from array import *
from heapq import *
from bisect import *
from functools import *
from itertools import *
from statistics import *
from collections import *
I = lambda : [*map(int, sys.stdin.readline().split())]
IP = lambda : map(int, input().split())
IS = lambda : input()
IN = lambda : int(input())
IF = lambda : float(input())

def f():
	(a, p) = (IN(), I())
	(b, q) = (IN(), I())
	(c, r) = (IN(), I())
	(d, s) = (IN(), I())
	for i in r:
		if i not in p:
			return 'no'
	for i in s:
		if i not in q:
			return 'no'
	return 'yes'
for _ in range(IN()):
	print(f())


for _ in range(int(input())):
	tr = int(input())
	ltr = list(map(int, input().split()))
	dr = int(input())
	ldr = list(map(int, input().split()))
	ts = int(input())
	lts = list(map(int, input().split()))
	ds = int(input())
	lds = list(map(int, input().split()))
	cnt1 = 0
	cnt2 = 0
	for i in lts:
		if i in ltr:
			cnt1 += 1
	for j in lds:
		if j in ldr:
			cnt2 += 1
	if cnt1 == len(lts) and cnt2 == len(lds):
		print('yes')
	else:
		print('no')


t = int(input())
for i in range(t):
	tr = int(input())
	trr = list(map(int, input().split()))
	dr = int(input())
	drr = list(map(int, input().split()))
	ts = int(input())
	tss = list(map(int, input().split()))
	ds = int(input())
	dss = list(map(int, input().split()))
	flag = True
	if set(trr) | set(tss) == set(trr) and set(drr) | set(dss) == set(drr):
		print('yes')
	else:
		print('no')


for x in range(0, int(input())):
	n = int(input())
	ramTruth = list(map(int, input().split()))
	n1 = int(input())
	ramDare = list(map(int, input().split()))
	n2 = int(input())
	shyamTruth = list(map(int, input().split()))
	n3 = int(input())
	shyamDare = list(map(int, input().split()))
	(flag, flag1) = (1, 1)
	for x in shyamTruth:
		if x not in ramTruth:
			flag = 0
	for x in shyamDare:
		if x not in ramDare:
			flag1 = 0
	if flag1 and flag:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	tr = int(input())
	trs = [int(x) for x in input().split()]
	dr = int(input())
	drs = [int(x) for x in input().split()]
	ts = int(input())
	tss = [int(x) for x in input().split()]
	ds = int(input())
	dss = [int(x) for x in input().split()]
	flag1 = 0
	flag2 = 0
	for i in tss:
		if i in trs:
			flag1 = 1
		else:
			flag1 = 0
			break
	for i in dss:
		if i in drs:
			flag2 = 1
		else:
			flag2 = 0
			break
	if flag1 == 1 and flag2 == 1:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	a = int(input())
	at = list(map(int, input().split()))
	b = int(input())
	bt = list(map(int, input().split()))
	c = int(input())
	ct = list(map(int, input().split()))
	d = int(input())
	dt = list(map(int, input().split()))
	k = 0
	for i in ct:
		if i not in at:
			k += 1
			break
	for i in dt:
		if i not in bt:
			k += 1
			break
	if k >= 1:
		print('no')
	else:
		print('yes')


try:
	t = int(input())
	result = []
	for i in range(t):
		check1 = True
		check2 = True
		tr = int(input())
		trl = list(map(int, input().split()))
		dr = int(input())
		drl = list(map(int, input().split()))
		ts = int(input())
		tsl = list(map(int, input().split()))
		ds = int(input())
		dsl = list(map(int, input().split()))
		for j in range(ts):
			if tsl[j] not in trl:
				check1 = False
			else:
				continue
		for k in range(ds):
			if dsl[k] not in drl:
				check2 = False
			else:
				continue
		if check1 == True and check2 == True:
			result.append('yes')
		else:
			result.append('no')
	for b in result:
		print(b)
except:
	pass


for _ in range(int(input())):
	input()
	t1 = list(map(int, input().split()))
	input()
	d1 = list(map(int, input().split()))
	input()
	t2 = list(map(int, input().split()))
	input()
	d2 = list(map(int, input().split()))
	flag = False
	for i in t2:
		if i not in t1:
			flag = True
			break
	if not flag:
		for i in d2:
			if i not in d1:
				flag = True
				break
	if flag:
		print('no')
	else:
		print('yes')


t = int(input())
for i in range(t):
	a = int(input())
	b = [int(i) for i in input().split()]
	c = int(input())
	d = [int(i) for i in input().split()]
	e = int(input())
	f = [int(i) for i in input().split()]
	g = int(input())
	h = [int(i) for i in input().split()]
	c1 = 0
	d1 = 0
	for i in f:
		if i in b:
			c1 += 1
		else:
			pass
	for i in h:
		if i in d:
			d1 += 1
		else:
			pass
	if c1 == e and d1 == g:
		print('yes')
	else:
		print('no')


for i in range(int(input())):
	trn = int(input())
	tr = input().split(' ')
	drn = int(input())
	dr = input().split(' ')
	tsn = int(input())
	ts = input().split(' ')
	dsn = int(input())
	ds = input().split(' ')
	for j in ts:
		if j not in tr:
			print('no')
			break
	else:
		for k in ds:
			if k not in dr:
				print('no')
				break
		else:
			print('yes')


for _ in range(int(input())):
	n1 = int(input())
	l1 = list(map(int, input().split()))
	n2 = int(input())
	l2 = list(map(int, input().split()))
	n3 = int(input())
	l3 = list(map(int, input().split()))
	n4 = int(input())
	l4 = list(map(int, input().split()))
	flag = 0
	for i in l3:
		if i not in l1:
			flag = 1
			break
	if flag == 0:
		for i in l4:
			if i not in l2:
				flag = 1
				break
	if flag == 0:
		print('yes')
	else:
		print('no')


for _ in range(int(input())):
	w = int(input())
	Lrt = list(map(int, input().split()))
	x = int(input())
	Lrd = list(map(int, input().split()))
	y = int(input())
	Lst = list(map(int, input().split()))
	z = int(input())
	Lsd = list(map(int, input().split()))
	ram_wins = 1
	for i in range(y):
		if Lst[i] not in Lrt:
			ram_wins = 0
			break
	if ram_wins:
		for i in range(z):
			if Lsd[i] not in Lrd:
				ram_wins = 0
				break
	if ram_wins:
		print('yes')
	else:
		print('no')


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	input()
	tr = set(map(int, input().split()))
	input()
	dr = set(map(int, input().split()))
	input()
	ts = set(map(int, input().split()))
	input()
	ds = set(map(int, input().split()))
	print('yes' if ts.issubset(tr) and ds.issubset(dr) else 'no')


t = int(input())
for _ in range(t):
	tr = int(input())
	tr1 = list(map(int, input().split()))
	dr = int(input())
	dr1 = list(map(int, input().split()))
	ts = int(input())
	ts1 = list(map(int, input().split()))
	ds = int(input())
	ds1 = list(map(int, input().split()))
	tt = 0
	for i in ts1:
		if i not in tr1:
			tt = 1
			break
	if tt == 0:
		for i in ds1:
			if i not in dr1:
				tt = 1
				break
	if tt == 1:
		print('no')
	else:
		print('yes')