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.*;
public class commonSub {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int t =scan.nextInt();
		for(int i = 0; i < t; i++) {
			int n = scan.nextInt();
			int m = scan.nextInt();
			ArrayList<Integer> a = new ArrayList<>();
			ArrayList<Integer> b = new ArrayList<>();
			for(int j = 0; j < n; j++) {
				a.add(scan.nextInt());
			}
			for(int j = 0; j < m; j++) {
				b.add(scan.nextInt());
			}
			TreeMap<Integer, Integer> tmap = new TreeMap<>();
			for(int j = 0; j < m; j++) {
				if(a.contains(b.get(j))) {
					if(!tmap.containsKey(b.get(j))) {
						tmap.put(b.get(j), 1);
					}else {
						tmap.put(b.get(j), b.get(j) + 1);
					}
				}
			}
			ArrayList<shared> share = new ArrayList<>();
			for(Integer x: tmap.keySet()) {
				shared add = new shared(x, tmap.get(x));
				share.add(add);
			}
			Collections.sort(share);
			if(!share.isEmpty()) {
				System.out.println("YES");
				System.out.print(share.get(0).amount + " " + share.get(0).value);
				System.out.println();
			}else {
				System.out.println("NO");
			}

		}
	}
}
class shared implements Comparable<shared>{
	public int value;
	public int amount;

	public shared(int v, int a) {
		value = v;
		amount = a;
	}

	public int compareTo(shared o) {
		if(amount != o.amount) return amount - o.amount;
		else {
			return value-o.value;
		}
	}

}
