t = int(input())
for i in range(t) :
	m,n = map(int,input().split())
	a = list(map(int,input().split()))
	b = list(map(int,input().split()))
	flag = False
	for i in a :
		if i in b :
			res = i
			flag = True
			break
	if flag :
		print("YES")
		print(1,res)
	else :
		print("NO")