t = int(input())
for _ in range(t):
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))

	lst = []
	for i in a:
		for q in b:
			if q == i and a != b:
				lst.append(q)
				break

	if a == b:
		lst.append(min(a))


	if len(lst) == 0:
		print("NO")
	else:
		print("YES")
		print(f'1 {lst[0]}')