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.*;

public class CodeForcesCompetetive {

	public static void main(String[] args) throws IOException,NumberFormatException {
		try {
			FastScanner sc=new FastScanner();
			int t=sc.nextInt();
			while(t-->0) {
				int n=sc.nextInt(),m=sc.nextInt();
				int a[]=new int[n];
				List<Integer> set1=new ArrayList<>();
				List<Integer> set2=new ArrayList<>();
 				for(int i=0;i<n;i++) {
					a[i]=sc.nextInt();
					set1.add(a[i]);
				}
				int b[]=new int[m];
				for(int i=0;i<m;i++) {
					b[i]=sc.nextInt();
					set2.add(b[i]);
				}
				List<Integer> list=new ArrayList<>();
				for(int i=0;i<n;i++) {
					if(set1.contains(a[i])&&set2.contains(a[i])) {
						list.add(a[i]);
						break;
					}
				}
				
				if(!list.isEmpty()) {
					System.out.println("YES");
					System.out.println(list.size()+" "+list.get(0));
				}
				else {
					list.add(a[0]);
					list.add(b[b.length-1]);
					if(list.size()<=a.length&&list.size()<=b.length) {
						System.out.println("YES");
						System.out.println(list.size()+" "+list.get(0)+" "+list.get(1));
					}
					else {
						System.out.println("NO");
					}
				}
				
				
			}
		}
		catch(Exception e) {
			return;
		}
	}
	
	
	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());
		}
		
	}

}
