#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
using namespace std;

struct clock{
int map[3][3];
int father,no;
}que[263000];
int start[3][3],temp[3][3];

int t[10]={0,65536,16384,4096,1024,256,64,16,4,1};
int change[9][9]={{1,1,0,1,1,0,0,0,0},
{1,1,1,0,0,0,0,0,0},
{0,1,1,0,1,1,0,0,0},
{1,0,0,1,0,0,1,0,0},
{0,1,0,1,1,1,0,1,0},
{0,0,1,0,0,1,0,0,1},
{0,0,0,1,1,0,1,1,0},
{0,0,0,0,0,0,1,1,1},
{0,0,0,0,1,1,0,1,1}};

int judge(int p[][3]){
int r=1; key=0;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++)
key=key+p[i][j]*t[r++];
if (hashs[key]!=0)  return 0;
hashs[key]=1;
return 1;
}
void move(int k){
int r=0;
for (int i=0; i<3; i++ )
for (int j=0; j<3; j++){
temp[i][j]+=change[k][r++];
temp[i][j]=temp[i][j]%4;
}
}
void find(int tail){
int t=tail;
last=0;
while (t!=1){
ans[++last]=que[t].no;
t=que[t].father;
}
}
void bfs()
{
memcpy( que[tail].map,start,sizeof(start));
judge(start);
for (int i=0;i<9; i++){
move(i);
if ( judge(temp) ){
memcpy(que[++tail].map,temp,sizeof(temp));
que[tail].no=i+1;
if (key==0){
find(tail);
return;
}
}
}
}
}

int main(){
int x;
for (int i=0; i<3; i++)
for (int j=0; j<3; j++){
scanf("%d",&start[i][j]);
}
bfs();
for (int i=last; i>=1; i--)
printf("%d ",ans[i]);
return 0;
}