q=int(input())
for i in range(q):
    d=[]
    a,b=input().split(' ')
    m=list(map(int,input().split()))
    z=list(map(int,input().split()))
    for j in range(len(m)):
        for k in range(len(z)):
            if m[j]==z[k]:
                d.append(m[j])
    if len(d)==0:
        print("NO")
    else:
        print("YES")
        print(1 ,end=' ')
        print(d[0])
            
                       