def ans():
	n,m=input().split()
	n=int(n)
	m=int(m)
	a=[int(x) for x in input().split()]
	b=[int(x) for x in input().split()]
	for i in b:
		if i in a:
			print("YES")
			print('1',end=" ")
			print(i)
			return
	print("NO")
	

t=int(input())
for i in range(t):
	ans()