#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e3+10;
typedef pair<int, int> PII;
int n;
int g[MAX][MAX];
PII pre[MAX][MAX], q[MAX*MAX];
int d[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
void bfs(int x, int y){
memset(pre, -1, sizeof pre);
int hh = 0, tt = 0;
pre[x][y] = {0, 0};
q[hh] = {x, y};
while(hh<=tt){
PII t = q[hh++];
for(int i=0; i<4; i++){
x = t.first+d[i][0], y = t.second+d[i][1];
if(x<0 || x>=n || y<0 || y>=n) continue;
if(pre[x][y].first!=-1) continue;
if(g[x][y]) continue;
pre[x][y] = t;
q[++tt] = {x, y};
}
}
}
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);
PII t(0, 0);
while(1){
printf("%d %d\n", t.first, t.second);
if(t.first==n-1 && t.second==n-1) break;
t = pre[t.first][t.second];
}
return 0;
}