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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Arrays;
import java.util.HashSet;

public class CommonSSeq {
    public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                        st=new StringTokenizer(br.readLine());				               
                                } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
    }
    public static void main(String[] args) 
    { 
		FastScanner s = new FastScanner();
		int T = s.nextInt();
		while(T-->0){
            int n = s.nextInt();
            int m = s.nextInt();
            Integer []arr1 = new Integer[n];
            Integer []arr2 = new Integer[m];
			for(int i = 0 ; i<n ; i++){
                arr1[i] = s.nextInt();
            }
            for(int i = 0 ; i<m ; i++){
                arr2[i] = s.nextInt();
            }
            Set<Integer> s1 = new HashSet<Integer>(Arrays.asList(arr1));
            Set<Integer> s2 = new HashSet<Integer>(Arrays.asList(arr2));
           s1.retainAll(s2);
           if(s1.size()>0){
            System.out.println("YES");
           System.out.println(s1.size() + " " + s1.toString().replace("[", "").replace("]", ""));
           }
           else{
               System.out.println("NO");
           }
		}
    }
}