t = int(input())


while t:

    m, n = [int(x) for x in input().split()]
    a = [int(x) for x in input().split()]
    b = [int(x) for x in input().split()]
    d = {}
    p = 'NO'
    for i in a:
        d[i] = True
    for j in b:
        if j in d:
            p = 'YES\n1 '+str(j)
            f = 1
            break

    print(p)

    t -= 1
