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.Arrays;

public class CommonSubsequence {
  
    public static void main(String[] args){
      try{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int aLength = 0, bLength = 0;
        String[] temp;
        int[] arr, brr;
        int index = -1;
        boolean commonFound = false;

        while(n-->0){
          temp = br.readLine().split(" ");
          aLength = Integer.parseInt(temp[0]);
          bLength = Integer.parseInt(temp[1]);
          arr = new int[aLength];
          brr = new int[bLength];
          temp = br.readLine().split(" ");
          for(int i = 0; i< aLength; i++){
            arr[i] = Integer.parseInt(temp[i]);
          }
          temp = br.readLine().split(" ");
          for(int i = 0; i < bLength; i++){
            brr[i] = Integer.parseInt(temp[i]);
          } 
          Arrays.sort(arr);
          for(int i = 0; i < bLength; i++){
             index = Arrays.binarySearch(arr, brr[i]);
             if(index != -1 ){
               commonFound = true;
               System.out.println("YES");
               System.out.println(1 + " " + brr[i]);
               break;
             }
          };

          if(!commonFound){
            System.out.println("NO");
          }
        }
      }catch(IOException ioe){
         ioe.printStackTrace();
      }
    }
}

