t=int(input())
while (t>0):
    t=t-1
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    k=0
    l=[]
    for i in range(len(a)):
        if (a[i] in b[:]):
            c=b.index(a[i])
            b=b[c:]
            k+=1
            l.append(a[i])
    if (len(l)==0):
        print("NO")
    else:
        print("YES")
        print(1,min(l))
            