1
2 2
1 1
1 2
 1
1 3
3
1 2 3
 1
1 1
1000
1000
 1
2 2
2 2
2 2
 5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
 1
4 4
1 1 1 1
1 2 3 4
 1
2 3
1 1
1 2 3

YES
1 1
 YES
1 3
 YES
1 1000
 YES
1 2
 YES
1 4
YES
1 3
NO
YES
1 3
YES
1 1
 YES
1 1
 YES
1 1

import java.io.*;
import java.util.*;

public class Main{ 
   static class Fast{
     public BufferedReader br;
     public StringTokenizer st;
     
     public Fast(){
          br =new BufferedReader(new InputStreamReader(System.in));
     }
     
     String next(){
          while(st==null || !st.hasMoreTokens()){
               try{
                    st=new StringTokenizer(br.readLine());
               }
               catch(IOException e){
                    throw new RuntimeException(e);
               }
               
          }
               return st.nextToken();
          }
     int nextInt(){
          return Integer.parseInt(next());
     }

     long nextLong(){
          return Long.parseLong(next());
     }

 }
  

	public static void main(String[] args)throws Exception{
         //StringTokenizer st;//! @ % & * () _ {} # ~ : < > ? "" | ^
          Fast f=new Fast();
         PrintWriter out = new PrintWriter(System.out);
        // StringBuilder str=new StringBuilder();
         //  int x=Integer.parseInt(st.nextToken());
         
        //st=new StringTokenizer(br.readLine()); 

        
        int t=f.nextInt();
        while(t-->0){
              int n=f.nextInt();
              int m=f.nextInt();

              Set<Integer> s=new HashSet<>();
              boolean k=false;
              int j=0;
               int x=0;
              for (int i=0;i<n;i++ ) {
                 x=f.nextInt();
                 s.add(x);
              }
               int b[]=new int[m];
              for (int i=0;i<m ;i++) {
                b[i]=f.nextInt();
              }

              for (int i=0;i<m ;i++) {
               if (s.contains(b[i])) {
                  k=true;j=i;break;
               }
              }
              


              if (k) {
                out.println("YES");
                out.println(1+" "+b[j]);
              }
              else out.println("NO");
             
        }
   
        //out.println(ans);
        
        //out.println(mh);
    out.close();

}
}


