import queue
print("Please input the size of the square:")
n = int(input())
map_ = [([0]*n) for i in range(n)]
vis = [([0]*n) for i in range(n)]
front = [([0]*n) for i in range(n)]
s,t = [0,0],[n-1,n-1]
xPos = [1,0,-1,0]
yPos = [0,1,0,-1]
def bfs(x,y):
q = queue.Queue()
q.put([x,y])
vis[x][y]=1
while q.qsize() != 0:
now = q.get()
if now == [n-1,n-1]:
return
for i in range(0,4):
xx = now[0] + xPos[i]
yy = now[1] + yPos[i]
if xx<0 or xx>n-1 or yy<0 or yy>n-1:
continue
elif map_[xx][yy] == 1 or vis[xx][yy]==1:
continue
else:
q.put([xx,yy])
vis[xx][yy]=1
front[xx][yy]=now
return
def printRoad():
q = queue.LifoQueue()
now=[n-1,n-1]
while now != [0,0]:
q.put(now)
now = front[now[0]][now[1]]
print("The road:")
while q.qsize():
temp = q.get()
print(temp)
for i in range(n):
map_[i] = input().split(" ")
map_[0][0]='S'
map_[n-1][n-1]='T'
bfs(0,0)
printRoad()
'''
input:
6
S 0 0 0 0 0
0 0 0 0 1 0
0 1 0 0 1 1
0 1 0 0 0 0
0 1 0 1 0 0
0 0 0 0 0 T
'''