t=int(input())
for i in range(t):
    n,m=[int(w) for w in input().split()]
    l1=[int(q) for q in input().split()]
    l2=[int(r) for r in input().split()]
    l3=[val for val in l1 if val in l2]
    l3.sort()
    if len(l3)>0:
        print('YES')
        print(1,l3[0])
    else:
        print('NO')