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

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	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[] line = br.readLine().split(" ");
            int n1 = Integer.parseInt(line[0]);
            int n2 = Integer.parseInt(line[1]);
            int[] a = new int[n1];
            int[] b = new int[n2];
            int index = 0;
            line = br.readLine().split(" ");
            for(String s : line) {
                a[index++] = Integer.parseInt(s);
            }
            index = 0;
            line = br.readLine().split(" ");
            for(String s : line) {
                b[index++] = Integer.parseInt(s);
            }
            Set<Integer> set = new HashSet<>();
            for(int i : a) {
                set.add(i);
            }
            int ans = -1;
            for(int i : b) {
                if(set.contains(i)) {
                    ans = i;
                    break;
                }
            }
            if(ans != -1) {
                System.out.println("YES");
                System.out.println("1 " + ans);
            }
            else {
                System.out.println("NO");
            }
        }
	}
}
