for _ in range(0,int(input())):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))

    aa=set(a)
    bb=set(b)

    cc=list(aa)
    cc+=list(bb)

    n1=len(cc)
    n2=len(set(cc))

    if n1==n2:
        print("NO")
    else:
        for i in cc:
            feq=cc.count(i)
            if feq==2:
                print("YES")
                print('1 ',i)
                break
