t=int(input())
for you in range(t):
    l=input().split()
    n=int(l[0])
    m=int(l[1])
    l=input().split()
    ai=[int(i) for i in l]
    l=input().split()
    bi=[int(i) for i in l]
    ans=0
    done=0
    hashi=dict()
    for i in ai:
        hashi[i]=1
    for i in bi:
        if(i in hashi):
            done=1
            ans=i
            break
    if(done):
        print("YES")
        print(1,end=" ")
        print(ans)
    else:
        print("NO")
