t=int(input())
for i in range(t):
         m,n=map(int,input().split())
         l1=list(map(int,input().split()))
         l2=list(map(int,input().split()))

         f=0
         for j in range(m):
                  if(l1[j] in l2):
                           print("YES")
                           print(1,l1[j])
                           f=1
                           break
         if(f==0):
                  print("NO")
                           
