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 CommonSubsequence {
    private static void solve(int [] A, int [] B, List<Integer> result, boolean flag) {
        for(int i = 0; i<A.length; i++) {
            for(int  j = 0; j<B.length; j++) {
                if(A[i] == B[j]) result.add(A[i]);
            }
        }
    }
    public static void main(String[] args) {
        Scanner sn = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();

        int T = sn.nextInt();
        while(T-- > 0) {
            int N = sn.nextInt();
            int M = sn.nextInt();

            int [] A = new int[N];
            for(int i = 0; i<N; i++) A[i] = sn.nextInt();

            int [] B = new int[M];
            for(int i = 0; i<M; i++) B[i] = sn.nextInt();

            List<Integer> result = new ArrayList<>();
            solve(A, B, result, true);
            if(result.size() == M && result.size() == N) {
                sb.append("YES").append("\n").append(1).append(" ").append(result.get(0)).append("\n");
            }
            else if(result.size() != 0) {
                sb.append("YES").append("\n").append(result.size()).append(" ");
                for(int num : result) sb.append(num).append(" ");
                sb.append("\n");
            } else {
                sb.append("NO").append("\n");
            }
        }
        System.out.println(sb);
    }
}
