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 CF658A 
{
	public static void main(String args[])throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		int t=Integer.parseInt(br.readLine());
		while(t-->0)
		{
			String s=br.readLine();
			String st[]=s.split(" ");
			int n=Integer.parseInt(st[0]), m=Integer.parseInt(st[1]);
			s=br.readLine();
			String str[]=s.split(" ");
			HashSet<String> h=new HashSet<>();
			for(int x=0;x<n;x++)
				h.add(str[x]);
			s=br.readLine();
			String stri[]=s.split(" ");		
			int f=0;
			for(int x=0;x<stri.length;x++)
			{
				if(h.contains(stri[x]))
				{
					f=1;
					System.out.println("YES\n1 "+stri[x]);
					break;
				}
			}
			if(f==0)
				System.out.println("NO");
		}
	}
}