T=int(input())
for _ in range(T):
	n,m=map(int,input().split())
	s1 = set(map(int,input().split()))
	s2 = set(map(int,input().split()))
	s3 = s1.intersection(s2)
	if len(s3)!=0:
	    print("YES")
	    print(1,list(s3)[0])
	else:
	    print("NO")