Your class recently got a maths assignment with 5 questions. There are N (≤ 20) students in the class and at most 2 people can collaborate. For each student, you know which problems they solved.

Find out if there exists a team of two students who can together solve all problems.

------ Input Format ------ 

The first line of input will contain a single integer T, denoting the number of test cases. T test cases follow.
- Each of the following test cases contains N + 1 lines, where N is the number of students in the class.
- The first line contains a single integer N.
- Each of the following N lines contains K_{i} + 1 positive integers separated by whitespaces.
- In the i^{th} line, the first positive integer K_{i} is the number of problems the i^{th} student can solve. The next K_{i} integers are x_{1}, x_{2}, \ldots, x_{K_{i}}, the indices of the problems this student can solve.

------ Output Format ------ 

The output must consist of T lines.
- Each line must contain a single string: The solution to the i^{th} test case as a YES or NO (where YES should be returned if some pairing of students is capable of solving all the problems, and NO otherwise). 

You may print each character of the string in uppercase or lowercase (for example, the strings YES, yEs, yes, and yeS will all be treated as identical). 

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$2 ≤ N ≤ 20$
$0 ≤ K_{i} ≤ 5$
$1 ≤ x_{i} ≤ 5$

----- Sample Input 1 ------ 
4
3
1 3
1 1
4 1 3 4 5
2
4 2 3 4 5
3 1 2 4
3
1 1
1 2
1 3
2
2 1 5
3 2 3 4

----- Sample Output 1 ------ 
NO
YES
NO
YES
----- explanation 1 ------ 
Test case $1:$ There is no student who solved the second question.

Test case $2:$ The second student can solve the first question and the first student can solve all the remaining problems, so they can form a team to solve all the problems together.

Test case $3:$ There is no student who solved fourth and fifth questions.

Test case $4:$ Given $2$ people can collaborate to solve all the problems.

Difficulty: MEDIUM

Solutions:
for _ in range(int(input())):
	n = int(input())
	l = []
	nu = []
	for i in range(n):
		a = list(map(int, input().split()))
		l.append(a[1:])
		nu.append(a[0])
	val = False
	for i in range(n):
		for j in range(n):
			c = l[i] + l[j]
			if set(c) == {1, 2, 3, 4, 5}:
				val = True
	if val == True:
		print('YES')
	else:
		print('NO')


from itertools import combinations

def can_solve_all_problems(N, student_problems):
	pairs = combinations(range(N), 2)
	for (i, j) in pairs:
		combined_problems = set(student_problems[i] + student_problems[j])
		if len(combined_problems) == 5:
			return 'YES'
	return 'NO'
T = int(input())
for _ in range(T):
	N = int(input())
	student_problems = []
	for _ in range(N):
		problems = list(map(int, input().split()))[1:]
		student_problems.append(problems)
	print(can_solve_all_problems(N, student_problems))


for _ in range(int(input())):
	N = int(input())
	arr = []
	for i in range(N):
		temp = list(map(int, input().split()))
		temp.pop(0)
		arr.append(temp)
	val = False
	for i in range(N):
		for j in range(N):
			temp0 = [0, 0, 0, 0, 0, 0]
			for x in arr[j]:
				temp0[x] = 1
			for x in arr[i]:
				temp0[x] = 1
			if sum(temp0) == 5:
				val = True
	if val == True:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	each = []
	for i in range(n):
		member = list(map(int, input().split()))
		member.pop(0)
		each.append(set(member))
	flag = 0
	for i in range(n - 1):
		for j in range(i + 1, n):
			if len(each[i].union(each[j])) == 5:
				print('YES')
				flag = 1
				break
		if flag:
			break
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	arr = []
	flag = 0
	for i in range(n):
		temp = [int(x) for x in input().split()]
		temp.pop(0)
		temp = set(temp)
		arr.append(temp)
	for i in range(len(arr)):
		for j in range(i, len(arr)):
			if len(arr[i].union(arr[j])) == 5:
				print('YES')
				flag = 1
				break
		if flag == 1:
			break
	if not flag:
		print('NO')


from math import sqrt, ceil, floor, gcd, log2
import sys
from sys import stdin, stdout
from collections import Counter, defaultdict, OrderedDict, deque
from itertools import combinations, groupby
from time import time
from heapq import heappop, heappush, heapify
t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for i in range(n):
		q = list(map(int, input().split()))
		q.pop(0)
		q = set(q)
		arr.append(q)
	flag = 0
	for i in range(len(arr)):
		for j in range(len(arr)):
			if i != j:
				if len(arr[i].union(arr[j])) == 5:
					print('YES')
					flag = 1
					break
		if flag:
			break
	if not flag:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	list1 = []
	for i in range(n):
		setofproblem = list(map(int, input().split()))
		list1.append(setofproblem[1:])
	flag = 0
	for i in list1:
		for j in list1:
			s = set(i + j)
			if len(s) == 5:
				print('YES')
				flag = 1
				break
		if flag:
			break
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	x = {1, 2, 3, 4, 5}
	ans = 'NO'
	c = 0
	a = []
	for i in range(n):
		a.append(list(map(int, input().split(' ')))[1:])
	for i in range(n):
		for j in range(n):
			if set(a[i] + a[j]) == x:
				ans = 'YES'
				c = 1
				break
		if a == 1:
			break
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	b = 1
	for i in range(n):
		k = list(map(int, input().split()))
		l.append(k[1:])
	for i in range(0, len(l)):
		if b == 0:
			break
		for j in range(i + 1, len(l)):
			if sum(set(l[i]) | set(l[j])) == 15:
				print('YES')
				b = 0
				break
	if b:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	s = set((1, 2, 3, 4, 5))
	tot = sum(s)
	for i in range(n):
		k = list(map(int, input().split()))
		arr.append([k[0], k[1:]])
	arr = sorted(arr, key=lambda x: x[0], reverse=True)
	flag = 0
	for i in range(n):
		if flag == 1:
			break
		a = arr[i]
		for j in range(i + 1, n):
			k = set()
			b = arr[j]
			k.update(a[1])
			k.update(b[1])
			if tot == sum(k):
				print('YES')
				flag = 1
				break
	if flag == 0:
		print('NO')


def solve(arr, n):
	if n == 1:
		return 'NO'
	for i in range(n):
		for j in range(i + 1, n):
			val = set(arr[i] + arr[j])
			if len(val) == 5:
				return 'YES'
	return 'NO'
for _ in range(int(input())):
	n = int(input())
	arr = []
	for i in range(n):
		val = [int(j) for j in input().split()]
		val.pop(0)
		arr.append(val)
	print(solve(arr, n))


t = int(input())
for _ in range(t):
	n = int(input())
	l = []
	for i in range(n):
		k = list(map(int, input().split()))
		l.append(k)
	f = 0
	for i in range(n):
		for j in range(i + 1, n):
			if l[i][0] + l[j][0] >= 5:
				h = [0] * 6
				for k in range(1, len(l[i])):
					h[l[i][k]] = 1
				for o in range(1, len(l[j])):
					h[l[j][o]] = 1
				if h[1:] == [1] * 5:
					f = 1
					print('YES')
			if f == 1:
				break
		if f == 1:
			break
	if f == 0:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	st = [0 for _ in range(n)]
	for i in range(n):
		tt = list(map(int, input().split()))
		tn = 0
		for xx in tt[1:]:
			tn = tn | 1 << xx - 1
		st[i] = tn
	ans = 0
	for i in range(n):
		if ans:
			break
		for j in range(i):
			if st[i] | st[j] == 31:
				ans = 1
				break
	if ans:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	setOfQuestions = {1, 2, 3, 4, 5}
	res = 'NO'
	flag = 0
	L = []
	for _ in range(n):
		L.append(list(map(int, input().split(' ')))[1:])
	for i in range(n):
		for j in range(n):
			if set(L[i] + L[j]) == setOfQuestions:
				res = 'YES'
				flag = 1
				break
		if flag == 1:
			break
	print(res)


for _ in range(int(input())):
	n = int(input())
	l = []
	for _ in range(n):
		l.append(set(list(map(int, input().split()))[1:]))
	v = {1, 2, 3, 4, 5}
	ok = False
	for i in range(n):
		for j in range(n):
			if l[i] | l[j] == v:
				ok = True
				break
		if ok:
			break
	print('YES' if ok else 'NO')


n1 = int(input())
while n1:
	flg = 1
	t = int(input())
	lst = []
	while t:
		x = list(map(int, input().split()))
		lst.append(x)
		t -= 1
	for i in range(len(lst)):
		for j in range(i + 1, len(lst)):
			if len(set(lst[i][1:] + lst[j][1:])) == 5:
				print('YES')
				flg = 0
				break
		if flg == 0:
			break
	if flg:
		print('NO')
	n1 -= 1


for _ in range(int(input())):
	n = int(input())
	mark = []
	for i in range(n):
		s = set(list(map(int, input().split()))[1:])
		mark.append(s)
	al = {1, 2, 3, 4, 5}
	bl = False
	for i in range(n):
		for j in range(n):
			if mark[i] | mark[j] == al:
				bl = True
				break
		if bl:
			break
	if bl:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	n = int(input())
	s = []
	for i in range(n):
		x = list(map(int, input().split()))
		s.append(x[1:])
	d = 0
	for i in range(len(s) - 1):
		for y in s[i + 1:]:
			x = set(s[i] + y)
			if len(x) == 5:
				d = 1
				break
		if d:
			break
	if d:
		print('YES')
	else:
		print('NO')
	t -= 1


tests = int(input())
for i in range(tests):
	students = int(input())
	arr = []
	for j in range(students):
		arr.append(set(map(int, input().split()[1:])))
	ans = 'NO'
	for j in range(students):
		for k in range(j + 1, students):
			if sum(arr[j] | arr[k]) == 15:
				ans = 'YES'
				break
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = []
	for i in range(n):
		nl = list(map(int, input().split()))
		l.append(nl[1:])
	f = 0
	for i in range(n - 1):
		l1 = l[i]
		for j in range(i, n):
			l2 = l[j]
			if sum(set(l1 + l2)) == 15:
				print('YES')
				f = 1
				break
		if f:
			break
	if f == 0:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	X = []
	flag = 0
	for tc in range(n):
		L = list(map(int, input().split()))
		if L[0] == 5:
			flag = 25
		elif L[0] == 3 or L[0] == 4:
			flag += 1
		X.append(L)
	if flag > 20:
		print('YES')
	elif flag > 0:
		f = False
		for i in range(n):
			if X[i][0] == 3 or X[i][0] == 4:
				for j in range(n):
					if (1 in X[i][1:] or 1 in X[j][1:]) and (2 in X[i][1:] or 2 in X[j][1:]) and (3 in X[i][1:] or 3 in X[j][1:]) and (4 in X[i][1:] or 4 in X[j][1:]) and (5 in X[i][1:] or 5 in X[j][1:]):
						f = True
						break
		if f:
			print('YES')
		else:
			print('NO')
	else:
		print('NO')


t = int(input())
while t != 0:
	t -= 1
	n = int(input())
	l = []
	for _ in range(n):
		s1 = list(map(int, input().split()))
		s1.pop(0)
		l.append(set(s1))
	flag = True
	for i in range(n):
		for j in range(i + 1, n):
			a = l[i]
			b = l[j]
			if a.union(b) == {1, 2, 3, 4, 5}:
				print('YES')
				flag = False
				break
		if flag == False:
			break
	if flag:
		print('NO')


for _ in range(int(input())):
	n = int(input())
	l = []
	for _ in range(n):
		temp = list(map(int, input().split()))
		l.append(temp[1:])
	k = len(l)
	flag = 'NO'
	for i in range(k):
		for j in range(i + 1, k):
			if len(set(l[i] + l[j])) == 5:
				flag = 'YES'
				break
	print(flag)


t = int(input())
while t != 0:
	n = int(input())
	l = []
	for j in range(n):
		y = list(map(int, input().split()))
		l.append(y[1:])
	count = 0
	for i in range(0, len(l)):
		l1 = []
		if count != 0:
			break
		for j in range(i + 1, len(l)):
			l1 = l[i] + l[j]
			l1 = list(set(l1))
			if len(l1) == 5:
				if 0 not in l1:
					print('YES')
					count = 1
					break
	if count == 0:
		print('NO')
	t -= 1


from sys import stdin
rd = stdin.readline
for _ in range(int(rd())):
	n = int(rd())
	l = []
	ans = 'NO'
	for i in range(n):
		x = list(map(int, rd().split()))
		(k, x) = (x[0], x[1:])
		l.append(x)
		if k == 5:
			ans = 'YES'
	for i in range(len(l)):
		for j in range(i, len(l)):
			if set(l[i]).union(set(l[j])) == set([p for p in range(1, 6)]):
				ans = 'YES'
	print(ans)


for _ in range(int(input(''))):
	x = int(input(''))
	flag = 0
	new_list = []
	for i in range(x):
		new = list(map(int, input('').split()))[1:]
		new_list.append(new)
	for i in range(x):
		for j in range(x):
			if len(set(new_list[i] + new_list[j])) == 5:
				flag = 1
	if flag == 0:
		print('NO')
	else:
		print('YES')


T = int(input())
for _ in range(T):
	N = int(input())
	l = []
	for i in range(N):
		l1 = list(map(int, input().split()))
		l2 = l1[1:]
		l.append(l2)
	c = 0
	d = 0
	for i in range(len(l)):
		l3 = []
		for k in range(1, 6):
			if k not in l[i]:
				l3.append(k)
		for j in range(i + 1, len(l)):
			c = 0
			for i in l3:
				if i in l[j]:
					c = c + 1
			if c == len(l3):
				d = d + 1
				break
	if d == 0:
		print('NO')
	else:
		print('YES')


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def outp(n):
	sys.stdout.write(str(n) + '\n')

def outlt(lst):
	sys.stdout.write(' '.join(map(str, lst)) + '\n')

def outplt(lst):
	sys.stdout.write('\n'.join(map(str, lst)))
ans = []
for _ in range(inp()):
	N = inp()
	K = [inlt() for n in range(N)]
	for n in range(N):
		K[n] = set(K[n][1:])
	an = 'NO'
	All = set([1, 2, 3, 4, 5])
	for i in range(N):
		for j in range(N):
			if K[i].union(K[j]) == All:
				an = 'YES'
				break
		if an == 'YES':
			break
	ans.append(an)
outplt(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l1 = []
	c = 0
	for i in range(n):
		l = list(map(int, input().split()))
		l1.append(l)
	for i in range(n):
		for j in range(i + 1, n):
			if len(set(l1[i][1:] + l1[j][1:])) == 5:
				c = 1
				break
		if c == 1:
			break
	if c == 0:
		print('NO')
	else:
		print('YES')


t = int(input())
for _ in range(t):
	N = int(input())
	l1 = []
	for _ in range(N):
		l = list(map(int, input().split(' ')))
		l1.append(l[1:])
	flag = False
	for i in range(N):
		for j in range(i + 1, N):
			if len(set(l1[i] + l1[j])) == 5:
				flag = True
				break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	arr = []
	for _ in range(n):
		temp = [int(i) for i in input().split(' ')]
		arr.append(temp)
	flg = False
	for i in range(n):
		for j in range(i + 1, n):
			if len(set(arr[i][1:] + arr[j][1:])) == 5:
				flg = True
				break
		if flg:
			break
	if flg:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	students = []
	for i in range(n):
		students.append(list(map(int, input().split()))[1:])
	ans = 'NO'
	for i in range(n):
		for j in range(i + 1, n):
			if len(set(students[i] + students[j])) == 5:
				ans = 'YES'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	lst = []
	for __ in range(n):
		lst.append(list(map(int, input().split()))[1:])
	res = []
	ans = False
	for i in range(n):
		for j in range(n - 1):
			if len(set(lst[i] + lst[j])) == 5:
				ans = True
				break
	if ans:
		print('YES')
	else:
		print('NO')


t = int(input())
for i in range(t):
	n = int(input())
	k = []
	for x in range(n):
		l = list(map(int, input().split()))
		l.pop(0)
		k.append(l)
	flag = 0
	for i in range(n):
		for j in range(n):
			if len(set(k[i] + k[j])) == 5:
				flag = 1
				break
		if flag:
			break
	if flag:
		print('YES')
	else:
		print('NO')


T = int(input())
for index in range(T):
	N = int(input())
	data = []
	for jIndex in range(N):
		data.append(list(map(int, input().split())))
	a = 0
	for x in range(N):
		for y in range(x + 1, N):
			ls_total = set(data[x][1:] + data[y][1:])
			if len(ls_total) == 5:
				print('YES')
				a = 1
				break
		if a == 1:
			break
	if a == 0:
		print('NO')


for i in range(int(input())):
	n = int(input())
	a = []
	flag = 0
	for _ in range(n):
		k = list(map(int, input().split(' ')))
		k.pop(0)
		a.append(k)
	for i in range(n - 1):
		for j in range(n):
			if len(set(a[i] + a[j])) == 5:
				flag = 1
				break
		if flag:
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


from bisect import bisect_left
from code import interact
from heapq import heapify, heappush, heappop
from collections import deque
import sys
from math import gcd, sqrt, log10, log2, floor, ceil, sqrt
input = sys.stdin.readline

def il():
	return [int(a) for a in input().strip().split()]

def ip():
	return input().strip()

def ii():
	return int(input())

def ot(in_p, *args, e=' '):
	if type(in_p) == list:
		print(*in_p, end=e)
	if type(in_p) == str or type(in_p) == int:
		print(in_p, end=e)
		for l in args:
			print(l, end=e)
	print()

def a_pwr_n(a, n, mod):
	if n == 1:
		return a % mod
	if n % 2 == 0:
		val = a_pwr_n(a, n // 2, mod)
		return val % mod * val % mod
	else:
		return a % mod * a_pwr_n(a, n - 1, mod) % mod

def rg(*ag):
	if len(ag) == 3:
		return range(ag[0], ag[1], ag[2])
	elif len(ag) == 2:
		return range(ag[0], ag[1])
	elif len(ag) == 1:
		return range(ag[0])
	else:
		raise 'invalid input'

def ispal(i, j, st):
	while i <= j:
		if st[i] == st[j]:
			i = i + 1
			j = j - 1
		else:
			return False
	return True
mod = 1000000000 + 7
dx = [-1, -2, 1, 2, 2, -2, -1, 1]
dy = [2, 1, 2, 1, -1, -1, -2, -2]
for _ in range(ii()):
	n = ii()
	li = []
	for i in range(n):
		l = list(map(int, input().split()))[1:]
		li.append(l)
	f = False
	for i in range(len(li)):
		for j in range(i + 1, len(li)):
			if len(set(li[i] + li[j])) == 5:
				f = True
	if f:
		print('YES')
	else:
		print('NO')


a = set()
b = {1, 2, 3, 4, 5}
for i in range(int(input())):
	flag = False
	ns = int(input())
	ls = {}
	for j in range(ns):
		ls[j] = tuple(map(int, input().split()))[1:]
	for k in range(len(ls) - 1):
		for f in range(k + 1, len(ls)):
			for p in list(ls[k]):
				a.add(p)
			for q in list(ls[f]):
				a.add(q)
			if a & b == b:
				flag = True
			a.clear()
	print('YES') if flag else print('NO')


t = int(input())
for _ in range(t):
	n = int(input())
	s = []
	ans = 'NO'
	for _ in range(n):
		l = list(map(int, input().split()))[1:]
		s.append(l)
		for i in range(len(s)):
			for j in range(len(s)):
				if len(set(s[i] + s[j])) == 5:
					ans = 'YES'
	print(ans)


no_of_test_cases = int(input())

def check_if_all_problems_are_solved(l):
	for i in range(1, 6):
		if i not in l:
			return False
	return True
for _ in range(no_of_test_cases):
	no_of_students = int(input())
	students = {}
	success = False
	for i in range(no_of_students):
		line = [int(x) for x in input().split()]
		students[i] = {'no_of_problems': line[0], 'indices': line[1:]}
	for (i, i_student) in students.items():
		i_no_of_problems = i_student['no_of_problems']
		i_indices = i_student['indices']
		for (j, j_student) in students.items():
			if j <= i:
				continue
			j_no_of_problems = j_student['no_of_problems']
			j_indices = j_student['indices']
			if i_no_of_problems + j_no_of_problems < 5:
				continue
			if check_if_all_problems_are_solved(i_indices + j_indices):
				print('YES')
				success = True
				break
		if success:
			break
	if not success:
		print('NO')


try:
	for _ in range(int(input())):
		n = int(input())
		sols = []
		ans = 0
		for i in range(n):
			num = 0
			a = 0
			for j in input().split():
				if a == 0:
					a = 1
					continue
				if j == '1':
					num |= 1
				elif j == '2':
					num |= 2
				elif j == '3':
					num |= 4
				elif j == '4':
					num |= 8
				elif j == '5':
					num |= 16
			sols.append(num)
		for i in range(len(sols) - 1):
			for j in range(i, len(sols)):
				if sols[i] | sols[j] == 31:
					ans = 1
					break
				if ans:
					break
		if ans:
			print('YES')
		else:
			print('NO')
except Exception as e:
	raise e


for _ in range(int(input())):
	n = int(input())
	questions = []
	ans = 'NO'
	for x in range(n):
		k = list(map(int, input().split()))[1:]
		questions.append(k)
	for i in range(n):
		for j in range(i + 1, n):
			if len(set(questions[i] + questions[j])) == 5:
				ans = 'YES'
				break
	print(ans)


for i in range(int(input())):
	n = int(input())
	a = []
	for i in range(n):
		b = list(map(int, input().split()))
		a.append(b[1:])
	c = 0
	res = [1, 2, 3, 4, 5]
	for i in range(len(a)):
		for j in range(len(a)):
			if sorted(list(set(a[j] + a[i]))) == res and i != j:
				print('YES')
				c += 1
				break
		if c > 0:
			break
	if c == 0:
		print('NO')


def hasAll(vals):
	for k in range(5):
		if k + 1 not in vals:
			return False
	return True

def fun(students):
	for i in range(n - 1):
		for j in range(i + 1, n):
			combined = students[i] + students[j]
			if hasAll(combined):
				return True
	return False
t = int(input())
for _ in range(t):
	n = int(input())
	students = []
	for __ in range(n):
		students.append(list(map(int, input().split()))[1:])
	print('YES' if fun(students) else 'NO')


for _ in range(int(input())):
	N = int(input())
	A = []
	for i in range(N):
		i = list(map(int, input().split()))[1:]
		A.append(i)
	ans = 'NO'
	for i in range(N):
		for j in range(i + 1, N):
			if len(set(A[i] + A[j])) == 5:
				ans = 'YES'
				break
	print(ans)


for _ in range(int(input())):
	n = int(input())
	p = []
	for i in range(n):
		l = list(map(int, input().split()))
		p.append(l)
	q = list(range(1, 6))
	f = 1
	for i in range(n):
		for j in range(n):
			res = list(set(p[i][1:] + p[j][1:]))
			if q == sorted(res):
				print('YES')
				f = 0
				break
		if f == 0:
			break
	else:
		print('NO')


for i in range(int(input())):
	x = []
	res = 'NO'
	n = int(input())
	for i in range(n):
		i = list(map(int, input().split()))[1:]
		x.append(i)
	for i in range(n):
		for j in range(i + 1, n):
			if len(set(x[i] + x[j])) == 5:
				res = 'YES'
				break
	print(res)