for _ in range(int(input())):

    n,m=map(int,input().split())

    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    k=0
    l=[]
    
    for index,i in enumerate(b):
        for j in range(k,len(a)):
            if a[j]==i:
                l.append(i)
                k=index
                break

    if len(l)!=0:
        print("YES")
        print("1",l[0])

    else:
        print("NO")
