t=int(input())
for T in range(t):
	n,m=map(int,input().split())
	a=list(map(int,input().split()))
	b=list(map(int,input().split()))
	x=-1
	for i in range(n):
		for j in range(m):
			if(a[i]==b[j]):
				x=a[i]
				break
	if(x==-1):
		print("NO")
	else:
		print("YES")
		print(1,x)