from sys import stdin,stdout
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
for _t in range(int(input())):
	n,m = gil()
	a = gil()
	b = gil()
	a.sort()
	b.sort()
	c = None
	i, j = 0, 0
	while i < n and j < m:
		x1 = a[i]
		x2 = b[j]
		if x1 == x2:
			c = x1
			break
			i += 1
			j += 1
		elif x1 > x2:
			j += 1
		else:
			i += 1
	if c:
		print("YES")
		print(1,c)
	else:
		print("NO")
			
