#include <iostream>
using namespace std;

const int all = (1 << 10) - 1;

int board[12][12];
int mask[12];
//int conv[(1<<10)+10];
int save[12];

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;
}

int main(){
	/*
	for(int line=0;line<1<<10;++line){
		int m = 0;

		for(int i=0;i<10;++i){
			if((line >> i) & 1){
				m ^= 7 << i;
			}
		}

		conv[line] = (m >> 1) & all;
	}*/

	int n;
	cin >> n;

	for(int t=0;t<n;++t){
		for(int y=0;y<10;++y){
			int m = 0;
			for(int x=0;x<10;++x){
				cin >> board[y][x];
			}
			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;

			save[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;

				save[y] = doit;
			}

			save[9] = prev;

			if(curr ^ prev){
				continue;
			}

			for(int y=0;y<10;++y){
				int m = save[y];
				for(int x=9;x>=0;--x){
					if(x != 9)cout << " ";
					cout << (((m >> x) & 1) ? 1 : 0);
				}
				cout << endl;
			}

			break;
		}
	}
	return 0;
}