test=int(input())
k=1
while(k<=test):
	k+=1
	[n,m] = list(map(int,input().split()))
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))

	count = [0 for i in range(1001)]
	flag=0
	for i in a:
		count[i]+=1
	for i in b:
		if(count[i]>=1):
			flag=1
			print("YES")
			print(1,end=" ")
			print(i)
			break
	if(flag==0):
		print("NO")