t = int(input())
while t > 0:
	t -= 1
	d = str(input())
	s = d.split()
	n = int(s[0])
	m = int(s[1])
	da = str(input())
	a = da.split()
	db = str(input())
	b = db.split()
	z = 0
	ans = ''
	for i in a:
		if i in b:
			ans = i
			z = 1
			break
	if z != 0:
		print("YES")
		print(1,ans)
	else:
		print("NO")