#include <iostream>
#include <cstring>

using namespace std;

const int dx[] = {0, -1, 0, 1, 0};
const int dy[] = {-1, 0, 0, 0, 1};

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 push(int y, int x) {
    for (int i=0; i<5; ++i) {
        if (valid(y + dy[i], x + dx[i])) {
            state[y + dy[i]][x + dx[i]] = 1 - state[y + dy[i]][x + dx[i]];
        }
    }
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int j=0; j<10; ++j) {
            if ((bt>>j) % 10 == 1) {
                push(0, j);
                ans[0][j] = 1 - ans[0][j];
            }
        }
        for (int i=1; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i-1][j] == 1) {
                    push(i, j);
                    ans[i][j] = 1 - ans[i][j];
                }
            }
        }
        bool ok = true;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][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;
}