t = int(input())
cases = []


for i in range(t):
	line = input().split()
	n = int(line[0])
	m = int(line[1])
	a = [int(item) for item in input().split()]
	b = [int(item) for item in input().split()]
	case = [a, b]
	cases.append(case)

for case in cases:
	a = case[0]
	b = case[1]
	a = list(set(a))
	b = list(set(b))

	for num in a:
		if num in b:
			print("YES")
			print(f"1 {num}")
			break
	else:
		print("NO")

