#include<bits/stdc++.h>
using namespace std;
const int N = 9, M = (1<<9)-1; //M = 111111111(B);
//如:位置(i, j)对应 00000100 从右到左第三位是1 表示3这个数可以填到(i, j)位置
string s;
int ones[M], val[M];
int row[N], col[N], cel[3][3];
void init(){
//val[]记录每个位置的对应的值,如:100(B)中1对应3 则val[4] = 3;
for(int i=0; i<N; i++) val[1<<i] = i+1;
//for(int i=0; i<M; i++) cout<< "val["<< i<< "] = "<< val[i]<< endl;
//ones[]记录每个数有几个位置是1 如3:000000011(B)有两个位置是1 ones[3] = 2;
for(int i=0; i<(1<<N); i++){
for(int j=0; j<N; j++){
ones[i] += i>>j & 1;
}
}
}
//返回(r, c)位置可以填的数;
int get(int r, int c){
return row[r]&col[c]&cel[r/3][c/3];
}
//set: true-放数字 false-还原;
void change(int r, int c, int n, bool set){
if(set) s[r*9 + c] = n + '0';
else s[r*9 + c] = '.';
int t = 1<<n-1;
if(!set) t = -t;
row[r] -= t;
col[c] -= t;
cel[r/3][c/3] -= t;
}
int lowbit(int x){
return x&-x;
}
bool dfs(int n){
if(n==0) return true;
//找可以填的数字最少的位置;
//这样在后面产生的分支较少;
int x, y, mx = 10, stat;
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(s[i*9+j]=='.'){
stat = get(i, j);
if(ones[stat]<mx){
x = i, y = j;
mx = ones[stat];
}
}
}
}
//lowbit() 只找到i最后一个1的位置,起到剪枝效果;
for(int i=get(x, y); i; i-=lowbit(i)){
int tmp = val[lowbit(i)];
change(x, y, tmp, true); //放数字;
if(dfs(n-1)) return true;
change(x, y, tmp, false); //还原;
}
return false;
}
int main(){
init();
while(cin>> s, s[0]!='e'){
for(int i=0; i<N; i++){
row[i] = col[i] = M; //初始状态,每行每列可以填的数字是1~9;
}
for(int i=0; i<3; i++){
for(int j=0; j<3; j++){
cel[i][j] = M; //初始状态,每个宫可以填的数字也是1~9;
}
}
int n = 0;
for(int i=0, k=0; i<N; i++){
for(int j=0; j<N; j++, k++){
//如果一个位置上已经有数字了,那么这个位置所在行、列、宫都不能再填这个数字;
if(s[k]!='.'){
change(i, j, s[k]-'0', true);
}
else n++;
}
}
dfs(n);
cout<< s<< endl;
}
return 0;
}