for i in range(int(input())):
	n,m = map(int,input().split())
	a = [int(i) for i in input().split()]
	b = set([int(i) for i in input().split()])

	r = ""

	for i in range(n):
		if a[i] in b:
			r = a[i]
			break

	if r!="":
		print("YES")
		print(1,r)
	else:
		print("NO")