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

	a=set(a)
	b=set(b)

	if len(a.intersection(b))>0:
		print("YES")
		for i in a.intersection(b):
			print(f"1 {i}")
			break
	else:
		print("NO")