yalei yalei
# z=[[4,1,2],[3,0,5],[6,7,8]]
# z=[[3, 4, 2, 1, 4], [4, 2, 3, 8, 9], [2, 1, 9, 5, 6], [4, 2, 3, 7, 8], [1, 2, 6, 4, 3]]
# x=5
# d=0
x=int(input())
d=int(input())
z=[]
for i in range(x):
z.append(list(map(int,input().split())))
t=0 #2
c=1
cn=0
nowx=int((x+1)/2)-1
nowy=int((x+1)/2)-1
h=""
def a(d):
global t,cn,c
cn+=1
if cn>=c: #==
cn=0
t+=1
if t==2:
t=0
c+=1
if d==0:
return 1
elif d==1:
return 2
elif d==2:
return 3
elif d==3:
return 0
return d
for i in range(x*x):
print(nowx,nowy)#
h+=str(z[nowx][nowy])
if d==1:
nowx-=1
elif d==2:
nowy+=1
elif d==3:
nowx+=1
elif d==0:
nowy-=1
d=a(d)
print(h)