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

public class Solution {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0 ; i < n ;i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int arr[] = new int [x];
			int arr2[] = new int [y];
			ArrayList<Integer> ans = new ArrayList<Integer>();
			for (int j = 0 ; j < arr.length ; j++) {
				arr[j] = sc.nextInt();
			}
			for (int j = 0; j < arr2.length; j++) {
				arr2[j] = sc.nextInt();
			}
			
			for (int k = 0 ; k < arr.length ; k++) {
				for (int j = 0 ; j < arr2.length ; j++) {
					if (arr[k] == arr2[j])
						ans.add(arr[k]);
				}
			}
			if (ans.size() == 0) {
				System.out.print("NO");
			}else {
				System.out.println("YES");
				System.out.print(ans.size() + " ");
				display(ans);
			}
			System.out.println();

		}
	}
	
	public static void display (ArrayList<Integer> ans) {
		for (int i = 0 ; i < ans.size(); i++) {
			System.out.print(ans.get(i) + " ");
		}
	}

}