for t in range(int(input())):
	n, m = map(int, input().split())
	A = set(map(int, input().split()))
	B = set(map(int, input().split()))

	flag = False

	for a in A:
		if a in B:
			print("YES")
			print(1, a)
			flag = True
			break

	if flag:
		continue
	
	print("NO")

	

