t  =int(input())
while t>0:
	n,m = map(int,input().split())
	a1 = list(map(int,input().split()))
	a2 = list(map(int,input().split()))
	d = {}
	for i in range(n):
		d[a1[i]] = 1
	p = 0
	ind = -1
	for i in range(m):
		if a2[i] in d.keys():
			p = 1
			ind = a2[i]
			break
	if p == 0:
		print("NO")
	else:
		print("YES")
		print(1,ind)
	t = t-1