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

	hashmap1 = [0 for a in range(0, 1005)]
	hashmap2 = [0 for a in range(0, 1005)]

	flag5=0

	for i in a:
		hashmap1[i]+=1

	for i in     b:
		hashmap2[i]+=1 


	for i in range(0, len(hashmap2)):
		if hashmap1[i]>0 and hashmap2[i]>0:
			print("YES")
			print(1, i)
			flag5=1
			break

	if flag5==0:
		print("NO")
