#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main(){
  int n;
  cin >> n;
  while(n-- > 0){
    int imap[11][11],syokurin[11][11];
    rep(i,10){
      rep(j,10){
	syokurin[i][j] = 0;
	cin >> imap[i][j];
      }
    }

    rep(i,10){
      rep(j,10){
	if(imap[i][j] == 0)continue;
	syokurin[i][j]++;
	rep(k,4){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(!(0<=nx && nx <10 && 0<=ny && ny <10))continue;
	  syokurin[ny][nx]++;
	}
      }
    }

    rep(i,10){
      rep(j,10){
	if(syokurin[i][j] == 1)cout << 0;
	else syokurin[i][j]%2 == 0?cout << 0:cout << 1;
	if(j!=9)cout << " ";
      }
      cout << endl;
    }
    if(n != 0)cout << endl;

  }
  return 0;
}