for _ in range(int(input())):
	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:
			flag=1
			z=a[i]
			break
	if flag==1:
		print("YES")
		print(1,z)
	else:
		print("NO")