#include <iostream>
using namespace std;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
int field[12][12];
int afield[12][12];

void search(int y,int x) {
  int sum = 0;
  if(field[y][x] == 1) sum++;
  for(int i=0;i<4;i++) {
    if(field[y+dy[i]][x+dx[i]] == 1) {
      sum++;
    }
  }

  if(sum >= 3) {
    afield[y][x] = 1;
    if(field[y][x] == 1) field[y][x] = 0;
    else field[y][x] = 1;
    for(int i=0;i<4;i++) {
      if(field[y+dy[i]][x+dx[i]] == 1) {
	field[y+dy[i]][x+dx[i]] = 0;
      }
      else if(field[y+dy[i]][x+dx[i]] == 0) {
	field[y+dy[i]][x+dx[i]] = 1;
      }
    }
  }
  return;
}

int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++) {

    for(int j=0;j<12;j++) { //init field
      for(int k=0;k<12;k++) {
	field[j][k] = 0;
	afield[j][k] = 0;
      }
    }

    for(int j=0;j<10;j++) { //input field
      for(int k=0;k<10;k++) {
	cin >> field[j+1][k+1];
      }
    }

    for(int j=0;j<10;j++) {
      for(int k=0;k<10;k++) {
	search(j+1,k+1);
      }
    }

    for(int j=0;j<10;j++) {
      for(int k=0;k<10;k++) {
	if(k != 0) cout << " ";
	cout << afield[j+1][k+1];
      }
      cout << endl;
    }
  }
}