#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 head,tail,ans[1000],hashs[263000],key,last;
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()
{
    head=0,tail=1;
    memcpy( que[tail].map,start,sizeof(start));
    judge(start);
    while (head<tail){
        head++;
        for (int i=0;i<9; i++){
            memcpy( temp,que[head].map,sizeof(temp));
            move(i);
            if ( judge(temp) ){
                memcpy(que[++tail].map,temp,sizeof(temp));
                que[tail].father=head;
                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;
}