t=int(input())
while t>0:
    n,m=[int(x) for x in input().split()]
    l1=list(map(int,input().split()))
    l2=list(map(int,input().split()))
    l1.sort()
    l2.sort()
    i=0
    j=0
    flag=0
    while(i<n and j<m):
        if l1[i]==l2[j]:
            print("YES")
            print("1",l1[i])
            flag=1
            break
        elif l1[i]<l2[j]:
            i+=1
        else:
            j+=1
    if flag==0:
        print("NO")
    t-=1
