#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int n;
    cin >> n;
    int state[10][10];
    int ans[10][10];
    while (n --) {
        memset(state, 0, sizeof(state));
        memset(ans, 0, sizeof(ans));
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cin >> state[i][j];
            }
        }
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][j] == 1) {
                    state[i][j]     = 1 - state[i][j];
                    state[i+1][j-1] = 1 - state[i+1][j-1];
                    state[i+1][j]   = 1 - state[i+1][j];
                    state[i+1][j+1] = 1 - state[i+1][j+1];
                    state[i+2][j]   = 1 - state[i+2][j];
                    ans[i+1][j] = 1;
                }
            }
        }
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}