#include <iostream>
using namespace std;

string board[9];
int I, J;

void fill ( int i0, int j0, int m, int n ) {
  if( board[I][J] != '0' )
    return;
  int left = 45, set = 0;
  for( int i=0; i<m; i++ ){
    for( int j=0; j<n; j++ ){
      char c = board[i+i0][j+j0] - '0';
      left -= c;
      set += c > 0;
    }
  }
  if( set == 8 )
    board[I][J] = left + '0';
}

int main () {
  int S;
  cin >> S;
  for( int s=1; s<=S; s++ ){
    cout << "Scenario #" << s << ":" << endl;

    //--- Read the board.
    for( int i=0; i<9; i++ )
      cin >> board[i];

    //--- Dance...
    for( int k=0; k<81; k++ ){
      for( I=0; I<9; I++ ){
        for( J=0; J<9; J++ ){
	  fill( I, 0, 1, 9 );
	  fill( 0, J, 9, 1 );
	  fill( I-I%3, J-J%3, 3, 3 );
	}
      }
    }

    //--- Answer.
    for( int i=0; i<9; i++ )
      cout << board[i] << endl;
    cout << endl;
  }
}
