# -*- coding: utf-8 -*-
"""
Created on Tue Jul 21 15:41:27 2020

@author: thiva
"""

t = int(input())
for i in range(t):
    n,m = map(int, input().split())
    A = set([int(s) for s in input().split()])
    B = set([int(s) for s in input().split()])
    C = A.intersection(B)
    
    if(C != set()):
        print('YES')
        print(1, C.pop())
    else:
        print('NO')
        
   
    
