t = int(input())
for _ in range(t):
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	l = []
	for i in b:
		for j in a:
			if i==j:
				l.append(i)
				break
	if l:
		print("YES")
		print(1, l[0])
	else:
		print("NO")