# -*- coding: utf-8 -*-
"""
Created on Fri Jul 24 09:49:04 2020

@author: Admin
"""

for _ in range(int(input())):
    nm = list(map(int, input().rstrip().split()))[:2]
    a = list(map(int, input().rstrip().split()))[:nm[0]]
    b = list(map(int, input().rstrip().split()))[:nm[1]]
    a.sort()
    b.sort()
    c=[]
    for i in b:
        if i in a:
            c.append(i)
    if len(c) > 0:
        print('YES')
        print(1, c[0])
    else:
        print('NO')
    
    
    
    
    