from sys import stdin
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gcl = lambda : list(g())

t, = gil()

for _ in range(t):
	n, m = gil()
	a = set(gil())
	b = gil()
	flag = True
	for ele in b :
		if ele in a:
			print("YES")
			print(1, ele)
			flag = False
			break
	if flag :
		print("NO")



