#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int n, g[N][N];
pair<int, int> pre[N][N], q[N * N];
void bfs(int x, int y)
{
memset(pre, -1, sizeof pre);
pre[x][y] = {0, 0};//初始化pre
int hh = 0, tt = -1;//手写队列
q[ ++ tt] = {x, y};
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
while(hh <= tt)
{
pair<int, int> t = q[hh ++];
for(int i = 0; i < 4; i ++)
{
int a = t.first + dx[i], b = t.second + dy[i];
if(a < 0 || a >= n || b < 0 || b >= n) continue;
if(g[a][b]) continue;
if(pre[a][b].first != -1) continue;
q[ ++ tt] = {a, b};
pre[a][b] = t;
}
}
}
int main()
{
scanf("%d", &n);//快读吧
for(int i = 0 ; i < n; i ++)
for(int j = 0; j < n; j ++)
scanf("%d", &g[i][j]);
bfs(n - 1, n - 1);//倒着搜一遍
pair<int, int> end(0, 0);
while(true)
{
printf("%d %d\n", end.first, end.second);
if(end.first == n - 1 && end.second == n - 1) break;
end = pre[end.first][end.second];//及时更新。
}
return 0;
}