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

public class d2A {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader file = new BufferedReader(new InputStreamReader(System.in));
		int inputs = Integer.parseInt(file.readLine());
		while(inputs-->0) {
			StringTokenizer st = new StringTokenizer(file.readLine());
			int n = Integer.parseInt(st.nextToken());
			int m = Integer.parseInt(st.nextToken());
			st = new StringTokenizer(file.readLine());
			HashSet<Integer> a = new HashSet<>();
			for(int i = 0; i < n; i++) {
				a.add(Integer.parseInt(st.nextToken()));
			}
			boolean found = false;
			st = new StringTokenizer(file.readLine());
			for(int i = 0; i < m; i++) {
				int num = Integer.parseInt(st.nextToken());
				if(!a.add(num) && !found) {
					found = true;
					System.out.println("YES");
					System.out.println("1 " + num);
				}
			}
			if(!found)
				System.out.println("NO");
		}

	}

}
