for _ in range(int(input())):
	n, m = map(int, input().split())
	a = list(map(int, input().split()))
	b = list(map(int, input().split()))
	run = False
	for i in a:
		for j in b:
			if i == j:
				run = True
				k = i
	if run == True:
		print("YES")
		print("1 " + str(k))
	else:
		print("NO")