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

#define MAX 12
#define INV (-1)

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

		//cout << "Shot: " << i << "," << j << endl;
	}

	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';
		}
	}
};
void DetermineShootingPoints(CMap &stm, CMap &ans){
	while( !stm.NoLight() ){
		vector< pair<int, int > > vt;
		bool bSCont = true;

		/* corner */
		{
			if( stm.m[1][1] == 1 ){
				if( stm.m[1][2] == 1 && stm.m[2][1] == 1 &&
					stm.m[2][2] == 0  ){
					stm.PassParticle( 1, 1 );
					ans.m[1][1] = 1;
				}
			}
			if( stm.m[1][MAX-2] == 1 ){
				if( stm.m[1][MAX-3] == 1 && stm.m[2][MAX-2] == 1 &&
					stm.m[2][MAX-3] == 0  ){
					stm.PassParticle( 1, MAX-2 );
					ans.m[1][MAX-2] = 1;
				}
			}
			if( stm.m[MAX-2][1] == 1 ){
				if( stm.m[MAX-3][1] == 1 && stm.m[MAX-2][2] == 1 &&
					stm.m[MAX-3][2] == 0  ){
					stm.PassParticle( MAX-2, 1 );
					ans.m[MAX-2][1] = 1;
				}
			}
			if( stm.m[MAX-2][MAX-2] == 1 ){
				if( stm.m[MAX-2][MAX-3] == 1 && stm.m[MAX-3][MAX-2] == 1 &&
					stm.m[MAX-3][MAX-3] == 0 ){
					stm.PassParticle( MAX-2, MAX-2 );
					ans.m[MAX-2][MAX-2] = 1;
				}
			}
		}

		/* deko */
		{
			const int ci[32] = {1,1,1,1,1,1,1,1,2,3,4,5,6,7,8,9,2,3,4,5,6,7,8,9,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2};
			const int cj[32] = {2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,MAX-2,2,3,4,5,6,7,8,9};

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

				for(int j = 0; j < sizeof(di)/sizeof(*di); ++j){
					if( stm.m[ci[i]+di[j]][cj[i]+dj[j]] == 1 )
						cnt1++;
				}
				if( cnt1 == 4 ){
					int ccnt1 = 0;
					const int ddi[] = {-1,-1, 1, 1};
					const int ddj[] = {-1, 1, 1,-1};

					for( int j = 0; j < sizeof(ddi)/sizeof(*ddi); ++j){
						if( stm.m[ci[i]+ddi[j]][cj[i]+ddj[j]] == 1 )
							++ccnt1;
					}
					if( ccnt1 == 1 ){
						stm.PassParticle( ci[i], cj[i] );
						ans.m[ci[i]][cj[i]] = 1;
					}
				}
			}
		}

		/* other */
		for(int i = 1; i < MAX - 1 && bSCont; ++i){
			for(int j = 1; j < MAX - 1 && bSCont; ++j){
				if( stm.m[i][j] == 1 ){
					const int di[4][5] = {
						{0,-1,-1,-1,0},
						{-1,-1,0,1,1},
						{0,1,1,1,0},
						{1,1,0,-1,-1}
					};
					const int dj[4][5] = {
						{-1,-1,0,1,1},
						{0,1,1,1,0},
						{1,1,0,-1,-1},
						{0,-1,-1,-1,0}
					};

					for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
						bool bCont = true;
						int tti, ttj;

						for(int l = 0; l < sizeof(*di)/sizeof(**di) && bCont; ++l){
							switch( k )
							{
								case 0: tti = i + 1; ttj = j; break;
								case 1: tti = i; ttj = j - 1; break;
								case 2: tti = i - 1; ttj = j; break;
								case 3: tti = i; ttj = j + 1; break;
							}
							if( stm.m[i+di[k][l]][j+dj[k][l]] != 0 )
							{
								tti = ttj = INV;
								bCont = false;
								break;
							}
						}
						if( bCont ){
							if( inRange(tti,1,MAX-1) && inRange(ttj,1,MAX-1) &&
								(inRange(i+di[k][0],1,MAX-1) && inRange(j+dj[k][0],1,MAX-1)&&
								inRange(i+di[k][1],1,MAX-1) && inRange(j+dj[k][1],1,MAX-1)&&
								inRange(i+di[k][2],1,MAX-1) && inRange(j+dj[k][2],1,MAX-1)&&
								inRange(i+di[k][3],1,MAX-1) && inRange(j+dj[k][3],1,MAX-1)&&
								inRange(i+di[k][4],1,MAX-1) && inRange(j+dj[k][4],1,MAX-1))
								||
								((!inRange(i+di[k][0],1,MAX-1)||!inRange(j+dj[k][0],1,MAX-1))&&
								 (!inRange(i+di[k][1],1,MAX-1)||!inRange(j+dj[k][1],1,MAX-1))&&
								inRange(i+di[k][2],1,MAX-1) && inRange(j+dj[k][2],1,MAX-1)&&
								inRange(i+di[k][3],1,MAX-1) && inRange(j+dj[k][3],1,MAX-1)&&
								inRange(i+di[k][4],1,MAX-1) && inRange(j+dj[k][4],1,MAX-1)
								)
								||
								(inRange(i+di[k][0],1,MAX-1) && inRange(j+dj[k][0],1,MAX-1)&&
								 inRange(i+di[k][1],1,MAX-1) && inRange(j+dj[k][1],1,MAX-1)&&
								 (!inRange(i+di[k][2],1,MAX-1) || !inRange(j+dj[k][2],1,MAX-1))&&
								 (!inRange(i+di[k][3],1,MAX-1) || !inRange(j+dj[k][3],1,MAX-1))&&
								 (!inRange(i+di[k][4],1,MAX-1) || !inRange(j+dj[k][4],1,MAX-1))
								 )
								 )
							{
								vt.push_back( make_pair( tti, ttj ) );
							}
							if( inRange(tti,1,MAX-1) && inRange(ttj,1,MAX-1) &&
								inRange(i+di[k][0],1,MAX-1) && inRange(j+dj[k][0],1,MAX-1)&&
								(!inRange(i+di[k][1],1,MAX-1)||!inRange(j+dj[k][1],1,MAX-1))&&
								(!inRange(i+di[k][2],1,MAX-1)||!inRange(j+dj[k][2],1,MAX-1))&&
								(!inRange(i+di[k][3],1,MAX-1)||!inRange(j+dj[k][3],1,MAX-1))&&
								inRange(i+di[k][4],1,MAX-1)&&inRange(j+dj[k][4],1,MAX-1) )
							{
								int cnt1 = 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( stm.m[tti+di[k]][ttj+dj[k]] == 1 )
										cnt1++;
								}
								if( cnt1 == 5 ){
									stm.PassParticle( tti, ttj );
									ans.m[tti][ttj] = 1;
								}
							}
						}
					}
				}
			}
		}

		if( vt.size() > 0 )
		{
			int ti = INV, tj = INV;
			int max1 = 0;
			double maxEfficient = 0.499;
			
			for(unsigned int t = 0; t < vt.size(); ++t){
				int cnt1 = 0;
				int invCnt = 0;
				const int di[] = {0,-1,0,1,0,-1,-1,1,1};
				const int dj[] = {0,0,1,0,-1,-1,1,1,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
					if( !inRange(vt[t].first+di[k], 1, MAX-1) || !inRange(vt[t].second+dj[k],1,MAX-1) )
						invCnt++;
					if( stm.m[vt[t].first+di[k]][vt[t].second+dj[k]] == 1 )
						cnt1++;
				}

				if( cnt1 > max1 )
				{
					max1 = cnt1;
					if( (double)cnt1 / ( 5 - invCnt ) > maxEfficient )
					{
						maxEfficient = (double)cnt1 / (5 - invCnt);
						ti = vt[t].first;
						tj = vt[t].second;	
					}
				}
			}
			if( ti != INV && tj != INV )
			{
				stm.PassParticle( ti, tj );
				ans.m[ti][tj] = 1;
				bSCont = false;
			}
		}
	}
}
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];

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