import sys
infile = sys.stdin
next(infile)
for line in infile: 
    len = list(map(int, line.split()))
    n = len[0]
    m = len[1]
    a = list(map(int, infile.readline().split()))
    b = list(map(int, infile.readline().split()))
    k = []
    q=0
    for ai in a:
        for bi in b:
            if ai == bi:
                k.append(ai)
                q += 1
    if q!=0:
        print('YES')
        print('1 ' + str(k[0]))
    else:
        print('NO')
    