#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
 
int board[12][12];
int used[12];
int mask[12];
int all = (1 << 10) - 1;
 
int makeCurrMask(int curr, int m){
    for(int i=0;i<10;i++){
        if((m >> i) & 1){
            int t = (i == 0) ? (7 >> 1) : (7 << (i - 1));
            curr ^= t;
        }
    }
    return curr & all;
}

void solve(){
    memset(mask, 0, sizeof(mask));
    memset(used, 0, sizeof(used));
    for(int y=0;y<10;y++){
        int m = 0;
        for(int x=0;x<10;x++){
            m = ((m << 1) + board[y][x]);
        }
        mask[y] = m;
    }

    for(int line=0;line<1<<10;++line){
        int prev = makeCurrMask(mask[0], line);
        int curr = mask[1] ^ line;

        used[0] = line;

        for(int y=1;y<9;++y){
            int doit = prev;
            int nprev = makeCurrMask(curr, doit);
            int ncurr = mask[y+1] ^ doit;

            prev = nprev;
            curr = ncurr;

            used[y] = doit;
        }

        used[9] = prev;

        if(curr ^ prev){
            continue;
        } else {
            break;
        }
    }
}
 
void output(){
    for(int y=0;y<10;y++){
        int m = used[y];
        for(int x=9;x>=0;x--){
            if(x != 9)cout << " ";
            cout << (((m >> x) & 1) ? 1 : 0);
        }
        cout << endl;
    }
}

int main()
{
    int n;
    cin >> n;
 
    for(int t=0;t<n;t++){
        for(int y=0;y<10;y++){
            for(int x=0;x<10;x++)cin >> board[y][x];
        }
        solve();
        output();
    }
    return 0;
}