#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],solve[11][11];
    rep(i,10){
      rep(j,10){
	syokurin[i][j] = solve[i][j] = 0;
	cin >> imap[i][j];
      }
    }

    while(true)
      {
	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)continue;
	    if(syokurin[i][j]%2 != 0){
	      solve[i][j] = 1;
	      imap[i][j] = imap[i][j] == 0?1:0;
	      rep(k,4){
		int nx = j+dx[k],ny = i+dy[k];
		if(!(0<=nx && nx <10 && 0<=ny && ny <10))continue;
		imap[ny][nx] = imap[ny][nx]==0?1:0;
	      }
	    }
	  }
	}

	rep(i,10)rep(j,10)syokurin[i][j] = 0;
	bool fin = true;
	rep(i,10)rep(j,10)if(imap[i][j] == 1)fin = false;
	  if(fin)break;
      }

    rep(i,10){
      rep(j,10){
	cout << solve[i][j];
	if(j != 9)cout << " ";
      }
      cout << endl;
    }
    
  }
  return 0;
}