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

public class xyz {
    static ArrayList<Integer>[] a,b;

    static int BinSearch(int x,ArrayList<Integer> a)
    {
        int l=0,r=a.size()-1;
        while(l<=r)
        {
            if(l==r)
            {
                if(a.get(l)==x)
                {
                    return l;
                }
                else
                {
                    return -1;
                }
            }
            else if(x>a.get((l+r)/2))
            {
                l=(l+r)/2+1;
            }
            else if(x<a.get((l+r)/2))
            {
                r=(l+r)/2-1;
            }
            else
            {
                return ((l+r)/2);
            }
        }
        return -1;
    }
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        int t=in.nextInt();
        int n,m,s,k=0;
         a=(ArrayList<Integer>[]) new ArrayList[t];
        b=(ArrayList<Integer>[]) new ArrayList[t];
        for(int i=0;i<t;i++) {
            a[i] = new ArrayList<Integer>();
            b[i] = new ArrayList<Integer>();
            n = in.nextInt();
            m = in.nextInt();
            for (int j = 0; j < n; j++) {
                a[i].add(in.nextInt());
            }
            for (int j = 0; j < m; j++) {
                b[i].add(in.nextInt());
            }
        }
        for(int i=0;i<t;i++)
        {
            n=a[i].size();
            m=b[i].size();
            if(n>m)
            {
                for(int j=0;j<m;j++)
                {
                    s=BinSearch(b[i].get(j),a[i]);
                    if(s!=-1) {
                        System.out.println("YES");
                        System.out.println(1+" "+b[i].get(j));

                        k=1;
                        break;
                    }
                }
               if(k==0) System.out.println("NO");
            }
            else
            {
                for(int j=0;j<n;j++)
                {
                    s=BinSearch(a[i].get(j),b[i]);
                    if(s!=-1) {
                        System.out.println("YES");
                        System.out.println(1+" "+a[i].get(j));
                        k=1;
                        break;
                    }
                }
               if(k==0) System.out.println("NO");
            }

 k=0;
        }
    }
}
