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.*;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.*;

public class Solution {
	public static void main(final String args[]) throws IOException {
		//getDataFromFile();
		final Scanner in = new Scanner(System.in);
		// BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		int t=in.nextInt();
		while(t-->0)
		{
			int m,n;
			m=in.nextInt();
			n=in.nextInt();
			int a[]=new int[m];
			int b[]=new int[n];
			Set<Integer> seta = new TreeSet<Integer>();
			for(int i=0;i<m;i++)
			{
				a[i]=in.nextInt();
				seta.add(a[i]);
			}
			boolean flag=false;
			for(int i=0;i<n;i++)
			{
				b[i]=in.nextInt();
				if(seta.contains(b[i]))
				{
					flag=true;
					System.out.println("YES");
					System.out.println("1 "+b[i]);
					break;
				}
		
			}
			if(!flag)
			{
				System.out.println("NO");
			}



			

		}
		
		in.close();
	}


	
	
	static void getDataFromFile() {
		try {
			final FileInputStream fin = new FileInputStream(new File("input.txt"));
			System.setIn(fin);
			PrintStream o = null;
			PrintStream err = null;
			o = new PrintStream(new File("output.txt"));
			err = new PrintStream(new File("error.txt"));
			System.setOut(o);
			System.setErr(err);
		} catch (final FileNotFoundException e) {
			e.printStackTrace();
		}
	}

}