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.*;
import java.io.*;
public class Test {
	public static void main(String [] args) throws IOException
	{
		Scanner s=new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		StringBuilder sb=new StringBuilder();
		int t=s.nextInt();
		int n,m;
		int size=0;
		int []a;
		int []b;
		int i,j,k;
		boolean flag;
		for ( i=0; i<t;i++)
		{
			flag=false;
			n=s.nextInt();
			m=s.nextInt();
			a=new int [n];
			b=new int [m];
			for (j=0;j<n;j++)
				a[j]=s.nextInt();
			for (k=0;k<m;k++)
				b[k]=s.nextInt();
			for (k=0;k<a.length;k++)
			{
				for ( j=0; j<b.length;j++)
				{	if (a[k]==b[j])
					{
						flag=true;
						break;
					}
				}
			if (flag)
				break;
			}
		if (flag)
		{
			pw.println("YES");
			pw.println("1"+a[k]);
		}
		else
			pw.println("NO");


		}
		pw.flush();



	}















	 static class Scanner
{
	StringTokenizer st;
	BufferedReader br;

	public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

	public String next() throws IOException
	{
		while (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(br.readLine());
		return st.nextToken();
	}

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

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

	public String nextLine() throws IOException {return br.readLine();}

	public double nextDouble() throws IOException
	{
		String x = next();
		StringBuilder sb = new StringBuilder("0");
		double res = 0, f = 1;
		boolean dec = false, neg = false;
		int start = 0;
		if(x.charAt(0) == '-')
		{
			neg = true;
			start++;
		}
		for(int i = start; i < x.length(); i++)
			if(x.charAt(i) == '.')
			{
				res = Long.parseLong(sb.toString());
				sb = new StringBuilder("0");
				dec = true;
			}
			else
			{
				sb.append(x.charAt(i));
				if(dec)
					f *= 10;
			}
		res += Long.parseLong(sb.toString()) / f;
		return res * (neg?-1:1);
	}

	public boolean ready() throws IOException {return br.ready();}


}
}