for _ in range(input()):
    n,m=[int(i) for i in raw_input().split()]
    a=[int(i) for i in raw_input().split()]
    b=[int(i) for i in raw_input().split()]
    d={}
    for i in b:
        d[i]=1
    flag=0
    for i in a:
        if d.get(i,0)==1:
            flag=1
            val=i
            break
    if flag:
        print "YES"
        print 1,val
    else:
        print "NO"
