t=int(input())
for _ in range(t):
	# a=int(input())
	n,k=map(int,input().split())
	l1=list(map(int,input().split()))
	l2=list(map(int,input().split()))
	ans=-1
	for i in range(len(l1)):
		for j in range(len(l2)):
			if(l1[i]==l2[j]):
				ans=l1[i]
				break
	if(ans==-1):
		print("NO")
	else:
		print("YES")
		print(1,ans)
	