t=int(input())
for t1 in range(0,t):


	x,y=map(int,input().split())
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
	d={}
	for i in a:
		if i not in d:
			d[i]=0
		d[i]+=1
	f=0
	ans=[]
	for i in b:
		if i in d:
			ans.append(i)
			f=1
			break
	if f==1:
		print("YES")
		print(1,*ans)
	else:
		print("NO")