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 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner scan = new Scanner(new BufferedInputStream(System.in));
    int t = scan.nextInt();
    while (t-- > 0) {
      int n = scan.nextInt();
      int m = scan.nextInt();
      int[] arr1 = new int[n];
      int[] arr2 = new int[m];

      for (int i = 0; i < n; i++) {
        arr1[i] = scan.nextInt();
      }
      for (int i = 0; i < m; i++) {
        arr2[i] = scan.nextInt();
      }
      // List<List<Integer>> result= new ArrayList<>();
      List<Integer> sht = new ArrayList<>();
      for (int i = 0; i < n; i++) {
        int index = i;
        List<Integer> list = new ArrayList<>();
        for (int j = 0; j < m; j++) {
          if (index < n && arr1[index] == arr2[j]) {
            list.add(arr2[j]);
            index++;
          }
        }
        if (sht == null || sht.size() == 0 || sht.size() > list.size()) {
          sht = list;
        }
        // result.add(list);
      }
      if (sht.size() == 0) {
        System.out.println("NO");
      } else {
        System.out.println("YES");
        for (int num : sht) {
          System.out.print(sht.size() + " " + num);
        }
        System.out.println();
      }
    }
  }
}