# -*- coding: utf-8 -*-

t = int(input())

for i in range(t):
    n,m = map(int,input().split())
    a = set(input().split())
    inter = a.intersection(input().split())
    if len(inter) < 1: print('NO')
    else:
        print('YES')
        print(1,list(inter)[0])
    
