t=int(input())
for i in range(t):
	f=0
	n,m=map(int,input().split())
	n1=list(map(int,input().split()))
	n2=list(map(int,input().split()))
	for j in range(n):
		if n1[j] in n2:
			print("YES")
			print(1,n1[j])
			f=1
			break
			f=0
	if f==0:
		print('NO')