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.InputStreamReader;
import java.util.ArrayList;

public class CommonSubsequence {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int casos = Integer.parseInt(br.readLine());
			while(casos-- > 0) {
				String datos[] = br.readLine().split(" ");
				int n = Integer.parseInt(datos[0]);
				int m = Integer.parseInt(datos[1]);
				String arr1 = br.readLine() + " ";
				String arr2[] = br.readLine().split(" ");
				ArrayList<String> arr3 = new ArrayList<String>();
				calcular(m, arr1, arr2, arr3);
				if(arr3.size() > 0) {
					System.out.println("YES");
					System.out.print(arr3.size() + " ");
					for(String x : arr3) {
						System.out.print(x + " ");
					}
					System.out.println();
				}else {
					System.out.println("NO");
				}				
			}			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private static void calcular(int m, String arr1, String[] arr2, ArrayList<String> arr3) {
		for(int i=0; i<m; i++) {
			if(arr1.lastIndexOf(arr2[i] + " ") != -1) {
				arr3.add(arr2[i]);
				return;
			}
		}
	}
}

 	   	   			   			   	  	 	  	