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.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
  static String join(List<Integer> s){
    StringBuilder sb = new StringBuilder();
    sb.append(s.get(0));
    for(int i=1; i<s.size(); i++)
      sb.append(" "+s.get(i));
    return sb.toString();
  }
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int nbTestCases = in.nextInt();
    for(int i=0; i<nbTestCases; i++){
      int al = in.nextInt();
      int bl = in.nextInt();
      HashMap<Integer, Integer> map = new HashMap<>();
      int k = 0;
      for(k=0; k<al; k++){
        int n = in.nextInt();
        map.put(n, map.getOrDefault(n,0)+1);
      }
      for(k=0; k<bl; k++){
        int n = in.nextInt();
        map.put(n, map.getOrDefault(n,0)+1);
      }

      List<Integer> res = new ArrayList<>();
      for(Entry<Integer, Integer> g : map.entrySet()){
        if(g.getValue() == 2){
          res.add(g.getKey());
          break;
        }
      }

      if(res.size() == 0)
        System.out.println("NO");
      else
      {
        Collections.sort(res);
        System.out.println("YES");
        System.out.println(res.size()+" "+join(res));
      }
    }
  }
}