def check(a,b):
    ans=[]
    for i in range(len(b)):
        for j in range(len(a)):
            if b[i]==a[j]:
                ans.append(a[j])
                return ans
    return ans
                
    




t=int(input())
for i in range(t):
    n,m=map(int,input().split())
    a=list(map(int,input().split()))
    b=list(map(int,input().split()))
    f=(check(a,b))
    if len(f)>0:
        print("YES")
        print(1,*f,sep=" ")
    else:
        print("NO")