n  = int(raw_input())
for _ in xrange(n):
    n, m = map(int,raw_input().split())
    nar = map(int, raw_input().split())
    mar = map(int, raw_input().split())

    fudeu = True
    for k in mar:
        if k in nar:
            fudeu = False
            print "YES"
            print 1, k
            break

    if fudeu: print  "NO"