#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
#include<cstdlib>

#define MAX 12

using namespace std;

inline bool inRange(int t, int min, int max){
	return (min <= t && t < max);
}

class CMap{
public:
	int m[MAX][MAX];

	CMap()
	{
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void Reset(){
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void PassParticle(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)
			if( inRange( i+di[k], 1, MAX - 1 ) && inRange( j + dj[k], 1, MAX - 1 ) )
				m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;
	}

	bool NoLight() const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}

	void Print() const
	{
		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';
		}
	}
	
	bool operator==(const CMap &t) const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( t.m[i][j] != m[i][j] )
					return false;
		return true;
	}
};

void BFS(CMap &stm, CMap &ret){
	vector< CMap > q;

	q.push_back( stm );

	while( !q.empty() ){
		CMap M = q[0];
		q.erase( q.begin() );

		if( M.NoLight() )
		{
			ret = M;
			break;
		}

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				CMap add;
				int cnt1 = 0;
				int cnt_valid = 0;
				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){
					if( M.m[i+di[k]][j+dj[k]] == 1 )
						++cnt1;
					if( inRange( i+di[k], 1, MAX - 1) && inRange( j+dj[k], 1, MAX-1 ) )
						++cnt_valid;
				}


				if( cnt1 >= 3 )
				{
					add = M;
					add.PassParticle( i, j );
					if( q.end() == find( q.begin(), q.end(), add ) )
						q.push_back( add );
				}
			}
		}
	}
}
void DetermineShootingPoints(CMap &stm, CMap &ans){
	while( !stm.NoLight() ){
		int max1 = 0;
		int pi, pj;

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				int cnt1 = 0;
				int cnt_valid = 0;
				const int di[] = {0,-1,0,1,0/*-1,-1,0,1, 1, 1, 0,-1*/};
				const int dj[] = {0,0,1,0,-1/* 0, 1,1,1,-0,-1,-1,-1*/};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
					if( stm.m[i+di[k]][j+dj[k]] == 1 )
						++cnt1;
					if( inRange( i+di[k], 1, MAX - 1) && inRange( j+dj[k], 1, MAX-1 ) )
						++cnt_valid;
				}

				if( cnt1 == cnt_valid ){
					stm.PassParticle( i, j );
					ans.m[i][j] = 1;
					goto RETRY;
				}

				if( cnt1 > max1 ){
					max1 = cnt1;
					pi = i;
					pj = j;
				}
			}
		}
		stm.PassParticle( pi, pj );
		ans.m[pi][pj] = 1;
RETRY:;
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D )
	{
		CMap M;
		CMap Answer;

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

		Answer.Reset();
		DetermineShootingPoints( M, Answer );
		Answer.Print();
	}
	return 0;
}