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.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.Set;

public class Main {

	public static void main (String[] args) throws java.lang.Exception
    {
		BufferedWriter log = new BufferedWriter(new OutputStreamWriter(System.out));
        InputReader in = new InputReader(System.in);
        int T = in.readInt();
        while(T-->0) {
        	int m = in.readInt();
        	int n = in.readInt();
        	int [] arr1 = IOUtils.readIntArray(in, n);
        	int [] arr2 = IOUtils.readIntArray(in, m);
        	Map<Integer,Integer> map1 = new HashMap<>();
        	Map<Integer,Integer> map2 = new HashMap<>();
        	for(int i = 0;i<n;i++) {
        		if(map1.containsKey(arr1[i])) {
        			map1.put(arr1[i], map1.get(arr1[i])+1);
        		} else { 
                    map1.put(arr1[i], 1); 
                } 
        	}
        	for(int i = 0;i<m;i++) {
        		if(map2.containsKey(arr2[i])) {
        			map2.put(arr2[i], map2.get(arr2[i])+1);
        		} else { 
                    map2.put(arr2[i], 1); 
                } 
        	}
        	Set<Integer> s = new HashSet<>(map1.keySet());
        	s.retainAll(map2.keySet());
        	// s has all the common elements in both arrays
        	int min = 0;
        	int give = 0;
        	for(int x:s) {
        		if(map1.containsKey(x)) {
        			if(map2.containsKey(x)) {
        				int val = Math.min(map1.get(x), map2.get(x));
        				if(val<min) {
        					min = val;
        					give = x;
        				}
        			}
        		}
        	}
        	if(min == 0) {
        		log.write("NO\n");
        		log.flush();
        	} else {
        		log.write("YES\n");
        		log.write("1 "+give);
        		log.flush();
        	}
        }
    }
}

class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;
    public InputReader(InputStream stream) {
        this.stream = stream;
    }
    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }
    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }
    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }
    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }
    public String next() {
        return readString();
    }
    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class IOUtils {
    public static int[] readIntArray(InputReader in, int size) {
        int[] array = new int[size];
        for (int i = 0; i < size; i++)
            array[i] = in.readInt();
        return array;
    }
}