from collections import Counter
t=int(input())
for _ in range(t):
	n,m=map(int,input().split())
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
	c1=Counter(a)
	c2=Counter(b)
	ans=-1
	for key,value in c1.items():
		if(c2[key]>0):
			ans=key
			break
	if(ans==-1):
		print("NO")
	else:
		print("YES")
		print(1,ans)
