import time s=time.time() f=[] n,k=list(map(int,input().split())) l=list(map(int,input().split())) for i in range(n): f.append(list(map(int,list(input())))) for i in range(k): nl=l[i] maxb=0 maxd=[0,0,0] c=n-nl+1 for x in range(c): for y in range(c): h=sum(f[x][y:y+nl]) w=0 #for z in range(nl): # w+=f[x+z][y] m=max([h,w]) if maxb=nl-2 if isbreak: break if isbreak: break fa,fb,fc=maxd for z in range(nl): f[fa+fc*z][fb+(fc-1)*(-z)]=not f[fa+fc*z][fb+(fc-1)*(-z)] put=str(fa+1)+" "+str(fb+1)+" " if fc: put+=str(fa+nl)+" "+str(fb+1) else: put+=str(fa+1)+" "+str(fb+nl) print(put) print(time.time()-s) for i in f: print(list(map(int,i)))