#include <iostream>
#include <cstring>

using namespace std;

int state[10][10];
int ans[10][10];

inline bool valid(int i, int j) {
    return 0 <= i && i < 10 && 0 <= j && j < 10;
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if ((i == 0 && (bt>>j) % 10 == 1) || (i != 0 && state[i][j] == 1)) {
                    state[i][j] = 1 - state[i][j];
                    if (valid(i+1, j-1)) state[i+1][j-1] = 1 - state[i+1][j-1];
                    if (valid(i+1, j))   state[i+1][j]   = 1 - state[i+1][j];
                    if (valid(i+1, j+1)) state[i+1][j+1] = 1 - state[i+1][j+1];
                    if (valid(i+2, j))   state[i+2][j]   = 1 - state[i+2][j];
                    ans[i][j] = 1;
                }
            }
        }
        bool ok = true;
        for (int j=0; j<10; ++j) {
            if (state[9][j] == 1) ok = false;
        }
        if (ok) return ;
    }
}

int main() {
    int n;
    cin >> n;
    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];
            }
        }
        solve();
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}