#include <iostream>
#include <algorithm>
using namespace std;
int row[9], col[9], cell[3][3];//横,竖,3*3九宫格,1-9是否出现(2进制表示)
int map[1<<9], ones[1<<9];//map用来结合lowbit用,表示1的所在位数;ones用来统计二进制数有几位1
char str[100];
inline int lowbit(int x){//lowbit函数.eg:输入(10100)2,返回(100)2.return x &-x;}
inline voidinit(){//初始化横,竖,3*3九宫格数组for(int i =0; i <9; i ++) col[i]= row[i]=(1<<9)-1;for(int i =0; i <3; i ++){for(int j =0;j <3; j ++){
cell[i][j]=(1<<9)-1;}}}
inline int get(int x, int y){//取横,竖,3*3九宫格数组交集return row[x]& col[y]& cell[x /3][y /3];}
bool dfs(int cnt){if(!(cnt))returntrue;//寻找最少的选择
int minv =10;
int x, y;for(int i =0; i <9; i ++){for(int j =0; j <9; j ++){if(str[i *9+ j]=='.'){
int t = ones[get(i, j)];if(t < minv){
minv = t;
x = i, y = j;}}}}for(int i =get(x, y); i >0; i -=lowbit(i)){
int t = map[lowbit(i)];
row[x]-=1<< t;
col[y]-=1<< t;
cell[x /3][ y /3]-=1<< t;
str[x *9+ y]= t +'1';if(dfs(cnt -1))returntrue;
row[x]+=1<< t;
col[y]+=1<< t;
cell[x /3][y /3]+=1<< t;
str[x *9+ y]='.';}returnfalse;}
int main(){//初始化map,ones数组for(int i =0; i <9; i ++) map[1<< i]= i;for(int i =0; i <1<<9; i ++){
int s =0;for(int j = i; j >0; j -=lowbit(j)){
s ++;}
ones[i]= s;}while(cin >> str, str[0]!='e'){init();
int cnt =0;for(int i =0, k =0; i <9; i ++){for(int j =0; j <9; j ++, k ++){if(str[k]!='.'){
int t = str[k]-'1';
row[i]-=1<< t;
col[j]-=1<< t;
cell[i /3][j /3]-=1<< t;}else cnt ++;}}dfs(cnt);
cout << str << endl;}return0;}