include<bits/stdc++.h>
using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int t;scanf("%d",&t); while(t--) { char s1[9],s2[9],s3[9],s4[9],s5[9],s6[9],s7[9],s8[9],s9[9]; scanf("%s",s1); if(s1[0]=='1') s1[0]=(char)(s1[0]+1); else s1[0]=(char)(s1[0]-1);
scanf("%s",s2); if(s2[3]=='1') s2[3]=(char)(s2[3]+1); else s2[3]=(char)(s2[3]-1); scanf("%s",s3); if(s3[6]=='1') s2[6]=(char)(s3[6]+1); else s3[6]=(char)(s3[6]-1); scanf("%s",s4); if(s4[1]=='1') s4[1]=(char)(s4[1]+1); else s4[1]=(char)(s4[1]-1); scanf("%s",s5); if(s5[4]=='1') s5[4]=(char)(s5[4]+1); else s5[4]=(char)(s5[4]-1); scanf("%s",s6); if(s6[7]=='1') s6[7]=(char)(s6[7]+1); else s6[7]=(char)(s6[7]-1); scanf("%s",s7); if(s7[2]=='1') s7[2]=(char)(s7[2]+1); else s7[2]=(char)(s7[2]-1); scanf("%s",s8); if(s8[5]=='1') s8[5]=(char)(s8[5]+1); else s8[5]=(char)(s8[5]-1); scanf("%s",s9); if(s9[8]=='1') s9[8]=(char)(s9[8]+1); else s9[8]=(char)(s9[8]-1); cout<<s1<<"\n"; cout<<s2<<"\n"; cout<<s3<<"\n"; cout<<s4<<"\n"; cout<<s5<<"\n"; cout<<s6<<"\n"; cout<<s7<<"\n"; cout<<s8<<"\n"; cout<<s9<<"\n"; }
}
/* Sample Input 1 154873296 386592714 729641835 863725149 975314628 412968357 631457982 598236471 247189563
Sample Output(as per other online IDEs and CodeBLocks Ide) 254873296 386492714 729641735 853725149 975324628 412968347 632457982 598235471 247189562 */