for _ in range(int(input())):
	n,m=map(int,input().split())
	arr=list(map(int,input().split()))
	brr=list(map(int,input().split()))
	ans=-1
	for i in range(n):
		for j in range(m):
			if(brr[j]==arr[i]):
				ans=arr[i]
				break
		if(ans!=-1):
			break
	if(ans==-1):
		print("NO")
	else:
		print("YES")
		print(1,ans)