import sys
def input(): return sys.stdin.readline().strip()

t = int(input())
while t:
	t -= 1
	n, m = map(int, input().split())
	a = [int(i) for i in input().split()]
	b = [int(i) for i in input().split()]

	ele = -1
	for i in range(n):
		for j in range(m):
			if a[i] == b[j]:
				ele = a[i]
				break
		if ele > 0:
			break

	if ele > 0:
		print("YES")
		print(1, ele)
	else:
		print("NO")