#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

const int bans=10;
bool tans[bans][bans];
bool ans[bans][bans];
int ban[bans][bans];

main(){
  int n;
  cin>>n;
  while(n--){
    rep(i,bans)rep(j,bans)cin>>ban[i][j];

    int mina=bans*bans;
    rep(k,1<<bans){
      memset(ans,0,sizeof(ans));
      int tmin=0;
      rep(i,bans){
        rep(j,bans){
          int t=0;
          if(!i){
            ans[i][j]=!!(1<<i&k);
          }else{
            t=ans[i-1][j]+ban[i-1][j];
            if(j<bans-1)t+=ans[i-1][j+1];
            if(j)t+=ans[i-1][j-1];
            if(i>1)t+=ans[i-2][j];
            ans[i][j]=t%2;
          }
          tmin+=ans[i][j];
        }
      }
      int odd=0;
      rep(j,bans){
        int t=ans[bans-1][j]+ban[bans-1][j]+ans[bans-2][j];
        if(j<bans-1)t+=ans[bans-1][j+1];
        if(j)t+=ans[bans-1][j-1];
        odd+=t%2;
      }
      if(!odd && tmin<mina){
        memcpy(tans,ans,sizeof(ans));
        mina=tmin;
      }
    }
    rep(i,bans){
      rep(j,bans){
        if(j)cout<<" ";
        cout<<tans[i][j];
      }
      cout<<endl;
    }
  }
}