#include <iostream>
#include <string>

using namespace std;

bool solve( int data[10][10], int answer[10][10], int t )
{
	if( t == 8 ){
		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				if( data[j][i] == 1 ) return false;
			}
		}
		return true;
	}

	for( int i = 1;i < 9;i++ ){
		if( data[i][t] == 1 ){
			data[i][t] = !data[i][t];
			data[i - 1][t + 1] = !data[i - 1][t + 1];
			data[i][t + 1] = !data[i][t + 1];
			data[i + 1][t + 1] = !data[i + 1][t + 1];
			data[i][t + 2] = !data[i][t + 2];

			answer[i][t + 1] = 1;

		}
	}

	return solve( data, answer, t + 1 );

}



int main(int argc, char const* argv[])
{
	int data[10][10];
	int answer[10][10];
	int n;

	cin >> n;

	for( int k = 0;k < n;k++ ){

		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				cin >> data[j][i];
				answer[j][i] = 0;
			}
		}

		solve( data, answer, 0 );

		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				cout << ( (j == 0) ? "" : " " ) << answer[j][i];
			}
			cout << endl;
		}
	}
	return 0;
}