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.ArrayList;
import java.util.List;
import java.util.Scanner;

public class CommonSub 
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while(t-->0)
        {
            int n = sc.nextInt();
            int m = sc.nextInt();
            ArrayList<Integer> lin = new ArrayList<>(n);
            ArrayList<Integer> lim = new ArrayList<>(m);
            for(int i=0 ; i<n ; i++)
            lin.add(sc.nextInt());

            for(int i=0 ; i<m ; i++)
            lim.add(sc.nextInt());

            ArrayList<Object> lin1 = new ArrayList<>();
            ArrayList<Object> lim1 = new ArrayList<>();

            for(int i=0 ; i<lin.size() ; i++)
            {
                for(int j=i+1 ; j<=lin.size() ; j++)
                lin1.add(lin.subList(i, j).toString());
            }
            for(int i=0 ; i<lim.size() ; i++)
            {
                for(int j=i+1 ; j<=lim.size() ; j++)
                lim1.add(lim.subList(i, j));
            }

            ArrayList<Object> finalli = new ArrayList<>() ;

            if(n>m)
            {   int least  = n;
                int size = 0 ;
                for(int i=0 ; i<n ; i++)
                {   
                    if(lim1.contains(lin1.get(i)))
                    {   
                        size = lin1.get(i).toString().length();
                        if(size < least){
                        finalli = (ArrayList)lin1.get(i);
                        }
                }
                }
                if(size>0)
                {   
                    System.out.println("YES");
                    System.out.println(size+" "+finalli);
                }
                else
                System.out.println("NO");
            }
            else
            {
                int least  = m;
                int size = 0 ;
                for(int i=0 ; i<m ; i++)
                {   
                    if(lin1.contains(lim1.get(i)))
                    {   
                        size = lim1.get(i).toString().length();
                        if(size < least){
                        finalli = (ArrayList)lim1.get(i);
                        }
                }
                }
                if(size>0)
                {   
                    System.out.println("YES");
                    System.out.println(size+" "+finalli);
                }
                else
                System.out.println("NO");
            }
        }
    }
}