t=int(input())
for i in range(t):
	n,m=map(int,input().split(" "))
	List_1=[int(j) for j in input().split(" ")]
	List_2=[int(j) for j in input().split(" ")]
	c=0
	for i in range(n):
		if List_1[i] in List_2 :
			c+=1
			k=i
			break
	if c==0:
		print("NO")
	else:
		print("YES")
		print("1",end=" ")
		print(List_1[k])