def sol() :
    n,m = input().split()
    l1=input().split()
    l2=input().split()
    ok = -1
    for i in range(int(n)) :
        for j in range(int(m)) :
            if int(l1[i]) == int(l2[j]) :
                ok=int(l1[i])
                break
        if ok != -1 :
            break
            
    if ok==-1 :
        print('NO')
    else :
        print('YES\n1', ok)








for test in range(int(input())) : sol()
