t=int(input())

while t>0:
	a=[int(x)for x in input().split()]
	n=a[0];m=a[1];

	a=[int(x)for x in input().split()]
	b=[int(x)for x in input().split()]
	k=0

	for i in a:
		for j in b:
			if j==i:
				num=i
				k=1
				break

		if k==1:
			break

	if k==1:
		print("YES")
		print(1,num)
	else:
		print("NO")	
	t-=1