test = int(input())
for t in range(test):
	n,m = 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:
			print("YES")
			print(1, i)
			flag = True
			break

	if not flag:
		print("NO")
