
  
t=int(input())
for i in range(t):
   n,m=input().split()
   l=list(map(int,input().strip().split()))
   l1=list(map(int,input().strip().split()))
   flag=0
   for j in l:
       if j in l1:
           flag=1
           print("YES")
           print(1,end=" ")
           print(j)
           break
   if flag==0:
       print("NO")
           
       
         
 
          
  
       
       