for _ in range(int(input())):
	# n = int(input())
	n, m = map(int, input().split())
	# l = [list(map(int, input().split())) for i in range(n)]
	l1 = list(map(int, input().split()))
	l2 = list(map(int, input().split()))
	temp = 0
	flag = False
	for i in range(n):
		for j in range(m):
			if l1[i] == l2[j]:
				temp = l1[i]
				flag = True
				break

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