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.text.*;
import java.util.*;
import java.math.*;

public class Commonsubsequence {
	public static void main(String[] args) throws Exception {
		new Commonsubsequence().run();
	}

	public void run() throws Exception {
		FastScanner file = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		///
		int times = file.nextInt();
		for(int x = 0;x<times;x++) {
			HashSet<Integer> nums = new HashSet<Integer>();
			int a = file.nextInt(), b = file.nextInt();
			for(int y = 0;y<a;y++) {
				nums.add(file.nextInt());
			}
			boolean flag = false; int sav = 0;
			for(int y = 0;y<b;y++) {
				int n = file.nextInt();
				if(!nums.add(n)) {
					sav = n;
					flag =true;
				}
			}
			out.println(flag?"YES\n" + 1  + " " + sav : "NO"); 
			
		}
		///
		file.close();
		out.flush();
	}

	///
	static class FastScanner {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public FastScanner() {
			reader = new BufferedReader(new InputStreamReader(System.in), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}

		public long nextLong() {
			return Long.parseLong(next());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}

		public void close() throws IOException {
			reader.close();
		}
	}
}