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.util.*;

/**
 *
 * @author Aaryan
 */
public class HR {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
       int tc = input.nextInt();
       while(tc-->0){
           int n = input.nextInt();
           int m = input.nextInt();
           int c = Math.min(n, m);
           int d = Math.max(n, m);
           
           int a [] = new int[c];
           int b [] = new int[d];
           
           for(int i=0; i<a.length; i++){
               a[i]= input.nextInt();
           }
           for(int i=0; i<b.length; i++){
               b[i]= input.nextInt();
           }
           
           int res=0;
           int flag =0;
           for(int i =0; i<c; i++){
               for(int j=0; j<d; j++){
                   if(a[i]==b[j]){
                       res=a[i];
                       flag=1;
                       break;
                       
                   }
               }
               
           }
           
           if(flag==1){
               System.out.println("YES");
               System.out.println("1 "+res);
           }
           else{
               System.out.println("NO");
           }
           
           
       }
       
    }
}