for(r=readline;;r().length,p()){f=r(n=+r(d=[])).split('');o=[y=i=0];for(z=w=l=f.length;--l;o.push(w-l))d.push(r().split(''));for(z--;i