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

public class Practice1 {
   public static void main(String[] args) throws Exception {
        FastInput in = new FastInput();
            int t = in.nextInt();
            StringBuilder str = new StringBuilder();

            while(t-->0){
                int m = in.nextInt();
                int n = in.nextInt();
                int a[] = new int[m];
                int b[] = new int[n];
                for(int i = 0;i<m;i++) {
                	a[i] = in.nextInt();
                }
                for(int i = 0;i<n;i++) {
                	b[i] = in.nextInt();
                }
                Arrays.sort(a);
                Arrays.sort(b);
                int i = 0,j=0;
                boolean bol = true;
                while(i<m&&j<n) {
                	if(a[i]==b[j]) {
                		str.append("YES "+a[i]+"\n");
                		bol = false;
                		break;
                	}else if(a[i]>b[j]) {
                		j++;
                	}else {
                		i++;
                	}
                }
                if(bol) {
                	str.append("NO\n");
                }
            }
            System.out.println(str);
    }

}


class FastInput {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;

    String next() throws IOException {
        if (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    Integer nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    Long nextLong() throws IOException {
        return Long.parseLong(next());
    }
}