#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct item{
int t[10];
bool empty(){
for(int i=1;i<=9;i++)
if(t[i])return false;
return true;
}
};
struct Queue{
int t[40],top;
Queue(){
memset(t,0,sizeof(t));top=0;
}
void push(int x){t[++top]=x;}
void output(){
for(int i=1;i<=top;i++)
printf("%d ",t[i]);
}
};
bool operator<(Queue A,Queue B){
if(A.top!=B.top)return A.top<B.top;
int i;for(i=1;i<=min(A.top,B.top);i++){
if(A.t[i]!=B.t[i])
return A.t[i]<B.t[i];
}
return A.t[i]<B.t[i];
}
item operator+(item A,item B){
for(int i=1;i<=9;i++)
A.t[i]=(A.t[i]+B.t[i])%4;
return A;
}
item operator*(item A,int time){
for(int i=1;i<=9;i++)
A.t[i]=(A.t[i]*time)%4;
return A;
}
Queue ans;
item ope[12];
int cnt[10];bool suc=0;
void DFS(int step){
if(step>9){
item now=ope[0];
for(int i=1;i<=9;i++)
now=now+(ope[i]*cnt[i]);
if(now.empty()){
if(ans.top==0)
for(int i=1;i<=9;i++){
for(int j=1;j<=cnt[i];j++)
ans.push(i);
}
else{
Queue n;n=Queue();
for(int i=1;i<=9;i++){
for(int j=1;j<=cnt[i];j++)
n.push(i);
}
if(n<ans)ans=n;
}
}
return;
}
for(int i=0;i<4;i++){
cnt[step]=i;
DFS(step+1);
}
}
int main(){
for(int i=1;i<=9;i++)
scanf("%d",&ope[0].t[i]);
ope[1]=(item){0,1,1,0,1,1,0,0,0,0};//ABDE
ope[2]=(item){0,1,1,1,0,0,0,0,0,0};//ABC
ope[3]=(item){0,0,1,1,0,1,1,0,0,0};//BCEF
ope[4]=(item){0,1,0,0,1,0,0,1,0,0};//ADG
ope[5]=(item){0,0,1,0,1,1,1,0,1,0};//BDEFH
ope[6]=(item){0,0,0,1,0,0,1,0,0,1};//CFI
ope[7]=(item){0,0,0,0,1,1,0,1,1,0};//DEGH
ope[8]=(item){0,0,0,0,0,0,0,1,1,1};//GHI
ope[9]=(item){0,0,0,0,0,1,1,0,1,1};//EFHI
DFS(1);
ans.output();
return 0;
}