t=int(input())
for i in range(t):
	n,m=list(map(int,input().split(" ")))
	l1=set(map(int,input().split(" ")))
	l2=set(map(int,input().split(" ")))
	out=[]
	out.extend(l1)
	out.extend(l2)
	out.sort()
	flag=0
	for k in range(1,len(out)):
		if out[k-1]==out[k]:
			print("YES")
			print("1",out[k])
			flag=1
			break
	if flag==0:
		print("NO")