#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int inf=-1;
typedef pair <int,int> TP;
int a[5][5];
int m=0,n=0;
int d[5][5];
int dx[4]= {1,0,-1,0},dy[4]= {0,1,0,-1};
TP xxx[30];
void bfs()
{
queue<TP> que;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
d[i][j]=inf;
que.push(TP(0,0));
d[0][0]=0;
while(!que.empty())
{
TP p = que.front();
que.pop();
if(p.first==4&&p.second==4) break;
for(int i=0; i<4; i++)
{
int nx=p.first+dx[i],ny=p.second+dy[i];
if(0 <= nx && 0 <= ny && nx < n && ny < m && a[nx][ny]!=1&&d[nx][ny]==inf)
{
que.push(TP(nx,ny));
d[nx][ny]=d[p.first][p.second]+1;
}
}
}
}
int dfs(int x,int y)
{
if(x==0&&y==0) return 0;
xxx[d[x][y]].first=x,xxx[d[x][y]].second=y;
if(d[x-1][y]==d[x][y]-1) dfs(x-1,y);
else if(d[x+1][y]==d[x][y]-1) dfs(x+1,y);
else if(d[x][y-1]==d[x][y]-1) dfs(x,y-1);
else if(d[x][y]==d[x][y+1]-1) dfs(x,y+1);
}
int main()
{
m=5,n=5;
for(int i=0; i<5; i++)
for(int j=0; j<5; j++)
scanf("%d",&a[i][j]);
bfs();
dfs(4,4);
for(int i=0;i<d[4][4]+1;i++)
printf("(%d, %d)\n",xxx[i].first,xxx[i].second);
return 0;
}