#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>
const int H = 10;
const int W = 10;

int my[5] = {1, -1, 0, 0, 0};
int mx[5] = {0, 0, 1, -1, 0};

vector< vector<int> > ans;
set< vector< vector<int> > > S;

bool end(int v[H][W]){
  REP(i, H) REP(j, W) if(v[i][j] == 1) return false;
  return true;
}

bool next(int v[H][W], int y, int x){
  int a = 0, b = 0;
  REP(i, 5){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < H && nx < W){
      if(v[ny][nx]) ++a;
      else ++b;
    }
  }
  return a > b;
}

void rev(int v[H][W], int y, int x){
  REP(i, 5){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < H && nx < W) v[ny][nx] = (v[ny][nx] + 1) % 2;
  }
}

void dfs(int v[H][W], vector< vector<int> > &u){
  if(end(v)) { ans = u; return ; }
  if(S.find(u) != S.end()) return ;
  S.insert(u);
  REP(i, H){
    REP(j, W){
      if(!next(v, i, j) || u[i][j]) continue;
      rev(v, i, j);
      u[i][j] = 1;
      dfs(v, u);
      u[i][j] = 0;
      rev(v, i, j);
    }
  }
}

int main() {
  int T; cin >>T;
  REP(t, T){
    ans = vector< vector<int> >();
    S = set< vector< vector<int> > >();
    int v[H][W];
    REP(i, H) REP(j, W) cin >>v[i][j];
    vector< vector<int> > u(H, vector<int>(W, 0));
    dfs(v, u);
    REP(i, H){
      REP(j, W) cout <<ans[i][j] <<(j + 1 == W ? "" : " ");
      cout <<endl;
    }
  }
  return 0;
}