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.*;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;

public class A {

    private static void solve() throws Exception {
        int n = fs.nextInt();
        int m = fs.nextInt();
        int[] a = fs.readArray(n);
        int[] b = fs.readArray(m);
        HashSet<Integer> hs = new HashSet<>();
        for (int i : b) hs.add(i);
        for (int i = 0 ; i < n ; i ++ ) {
            if (hs.contains(a[i])) {
                out.println("YES");
                out.println(a[i]);
                return;
            }
        }
        out.println("NO");

    }

    private static FastScanner fs = new FastScanner();
    private static PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) throws  Exception{
        int T = fs.nextInt();
        for (int t = 0; t < T; t ++ ) {
            solve();
        }
        out.close();
    }

    static void debug(Object... O) {
        System.out.print("DEBUG ");
        System.out.println(Arrays.deepToString(O));
    }

    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) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextString() {
            return next();
        }
    }
}
