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()))
	flag=0
	for i in range(n):
		if(a[i] in b):
			ans=a[i]
			flag=1
			break
	if(flag==0):
		print("NO")
	else:
		print("YES")
		print("1",ans)