#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;
typedef vector< vector<int> > ivv;
typedef vector<int> iv;

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

class C{
  public:
    ivv u;
    int t, y, x;
    C(){}
    C(ivv _u, int _t, int _y, int _x){ u = _u; t = _t; y = _y; x = _x; }
};

queue<C> open;

void rev(ivv &v, 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;
  }
}

bool next(ivv v, ivv &u, int y, int x){
  REP(i, H) REP(j, W) if(u[i][j]) rev(v, i, j);
  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;
}


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

ivv bfs(ivv &v){
  open = queue<C>();
  ivv _u(H, iv(W, 0));
  open.push(C(_u, 0, 0, -1));
  while(!open.empty()){
    C tmp = open.front(); open.pop();
    ivv u = tmp.u; int t = tmp.t;
    if(end(v, u)) return u;
    FOR(y, tmp.y, H){
      REP(x, W){
        if(y == tmp.y && x <= tmp.x) continue;
        if(!u[y][x] && next(v, u, y, x)){
          rev(v, y, x);
          u[y][x] = true;
          open.push(C(u, t + 1, y, x));
          u[y][x] = false;
          rev(v, y, x);
        }
      }
    }
  }
  return ivv();
}

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