#include<iostream>
#define MAX 12
#define INFTY 1 << 28
using namespace std;

bool IsLeft(int m[MAX][MAX]){
	for(int i = 1; i < MAX - 1; ++i){
		for(int j = 1; j < MAX - 1; ++j){
			if( m[i][j] ) return true;
		}
	}
	return false;
}
void PassParticle(int m[MAX][MAX], int i, int j){
	const int di[] = {0,-1,0,1,0};
	const int dj[] = {0,0,1,0,-1};

	for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
		m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;
	}
}
void PrintMap(int m[MAX][MAX]){
	for(int i = 1; i < MAX - 1; ++i){
		cout << m[i][1];
		for(int j = 2; j < MAX - 1; ++j){
			cout << ' ' << m[i][j];
		}
		cout << '\n';
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D ){
		int pi, pj; /* 1ðÅà½­½]³¹çêéÀW */
		int M[MAX][MAX] = {{0,},};
		int Answer[MAX][MAX] = {{0,},};

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				cin >> M[i][j];
			}
		}

		while( IsLeft(M) ){
			int max1 = 0;
			int min0 = INFTY;
			for(int i = 1; i < MAX - 1; ++i){
				for(int j = 1; j < MAX - 1 ; ++j){
					int cnt1 = 0;
					int cnt0 = 0;
					const int di[] = {-1,0,1,0};
					const int dj[] = {0,1,0,-1};

					for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
						if( M[i+di[k]][j+dj[k]] ) ++cnt1;
						else ++cnt0;
					}
					if( cnt1 > max1 && cnt0 < min0 )
					{
						pi = i; pj = j;
						max1 = cnt1;
						min0 = cnt0;
					}
				}
				
			}
			PassParticle( M, pi, pj );
			Answer[pi][pj] = 1;
		}
		PrintMap( Answer );
	}
	return 0;
}