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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class S {

  private static void process(int[] A, int[] B) {
    Set<Integer> s1 = new HashSet<>();
    Integer ans = null;

    for (int i = 0; i < A.length; i++) {
      s1.add(A[i]);
    }

    for (int i = 0; i < B.length; i++) {
      if (s1.contains(B[i])) {
        ans = B[i];
        break;
      }
    }

    if (ans == null) {
      System.out.println("NO");
    } else {
      System.out.println(1 + " " + ans);
    }
  }

  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    int T = Integer.parseInt(br.readLine());
    while (T-- > 0) {
      String[] inp = br.readLine().split(" ");
      int n = Integer.parseInt(inp[0]);
      int m = Integer.parseInt(inp[1]);
      int[] A = new int[n];
      int[] B = new int[m];

      inp = br.readLine().split(" ");
      for (int i = 0; i < inp.length; i++) {
        A[i] = Integer.parseInt(inp[i]);
      }

      inp = br.readLine().split(" ");
      for (int i = 0; i < inp.length; i++) {
        B[i] = Integer.parseInt(inp[i]);
      }

      process(A, B);
    }
  }

}
