kl=int(input())
for tr in range(kl):
    m, n = map(int, input().split())
    A=set(map(int, input().split()))
    B=set(map(int, input().split()))
    A.intersection_update(B)
    if len(A)==0:
        print('NO')
    else:
        print('YES')
        rz=[1]
        for a in A:
            rz+=[a]
            break
        print(*rz)
        