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.util.*;

public class Main 
{
	public static void main(String[] args) 
	{
		JScanner in = new JScanner();
		out = new StringBuilder();

		int t = in.nextInt();
		
		while(t-->0)
		{
			int n = in.nextInt();
			int m = in.nextInt();
			
			Map<Integer, Integer> a = new HashMap<>();
			for(int i=0; i<n; i++)
			{
				int akey = in.nextInt();
				a.put(akey, 1);
			}
			int key = -1;
			boolean stop = false;
			for(int i=0; i<m; i++)
			{
				key = in.nextInt();
				if(a.containsKey(key))
					stop = true;
				else if(!stop)
					key = -1;
			}
			out.append((key == -1)? "NO\n" :  "YES\n1 " + key + "\n");
			
		}
		
		System.out.println(out);
	}

	public static int max(int x, int y, int z)
	{
		return (int)Math.max(Math.max(x, y), z);
	}


	public static int min(int x, int y, int z)
	{
		return (int)Math.min(Math.min(x, y), z);
	}
	//sysout
	static StringBuilder out;
	//Scanner
	static class JScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}