
v=[]
for i in range(int(input())):

	n,m=map(int,input().split())
	a=list(set((map(int,input().split()))))
	b=list(set((map(int,input().split()))))
	# print(b)
	for i in a:
		for j in b:
			# print(i,j)
			if i==j:
				v.append(i)
				continue

	# print(v)
	# v.clear()
	for i in range(len(v)):
		if len(v)>0:
			print('YES')
			print('1',v[i],end='')
			print()
			v.clear()
		break
	else:
		print('NO')
		v.clear()