for _ in range(int(input())):
   n,m=map(int,input().split())
   s1=list(map(int,input().split()))
   s2=list(map(int,input().split()))
   L=[]
   if n>m:
      for i in range(n):
         if s1[i] in s2:
            L.append(s1[i]) 
   else:
      for i in range(m):
         if s2[i] in s1:
            L.append(s2[i]) 
   if len(L)==0:
      print("NO")
   else:
      print("YES")
      print(1,min(L))
         
      