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.math.*;
public class A
{
   public static void main(String[] args) throws Exception
   {
      Scanner sc=new Scanner(System.in);
      int T=0;
      if(sc.hasNextInt())
       T=sc.nextInt();
      while(T-->0)
      {
         int x=0,r1=0,r2=0;
         //int r1=0,r2=0;
         int s1=sc.nextInt();
         int s2=sc.nextInt();
         int[] a1=new int[s1];
         List<Integer> l=new ArrayList<>();
         for(int i=0;i<s1;i++)
         a1[i]=sc.nextInt();
         Arrays.sort(a1);
         for(int i=0;i<s2;i++)
         l.add(sc.nextInt());
         Collections.sort(l);
         
         for(int j=0;j<Math.min(s1,s2);j++)
         {
             if((r1==0)&&(l.contains(a1[j])))
             r1=a1[j];
             else if((r1!=0)&&(l.contains(a1[j])))
             r2=a1[j];
         }
         if(r1==0)
         System.out.println("NO");
         else if((r1!=0)&&(r2==0))
         {
           System.out.println("YES");
           if((s1==1)&&(s1==s2))
           System.out.println(1+" "+r1);
           else{
             x=Math.min(a1[0],l.get(0));                                                                                                             
             System.out.println(Math.min(x,r1)+" "+Math.max(x,r1));
           }
         }
         else if((r1!=0)&&(r2!=0))
         {
           System.out.println("YES");
           System.out.println(Math.min(r1,r2)+" "+Math.max(r1,r2));
         }
         //T--;
         
         }
         
         
      }
   }