t = int(input())
for _ in range(t):
	n, m = map(int, input().split())
	arr1 = [int(j) for j in input().split()]
	arr2 = [int(j) for j in input().split()]

	flag = -1
	for x in arr1:
		if x in arr2:
			flag = x
			break

	if flag == -1:
		print("NO")
	else:
		print("YES")
		print(1, flag)