t=int(input())
while t:
	n,m=[int(x) for x in input().split()]
	a=[int(x) for x in input().split()]
	b=[int(x) for x in input().split()]
	c=list(set(a).intersection(b))
	if len(c)==0:
		print("NO")
	else:
		print("YES")
		print(1,c[0])
	t-=1