#include <vector>
#include <iostream>
#include <list>

std::list<int> dfs(std::vector<std::vector<bool>> &state, const int &idx = 1) {
	if (idx < 10) {
		int res = 0;
		for (auto i = 0; i < 10; ++i) {
			res <<= 1;
			if (state.at(idx - 1).at(i)) {
				res += 1;
				for (const auto &index : { i - 1, i, i + 1 }) {
					if (index >= 0 && index < 10) {
						state.at(idx).at(index) = !state.at(idx).at(index);
					}
				}
				if (idx != 9) {
					state.at(idx + 1).at(i) = !state.at(idx + 1).at(i);
				}
			}
		}
		auto list = dfs(state, idx + 1);
		if (list.size() + idx == 9) {
			list.push_front(res);
			return list;
		}
		else {
			return list;
		}
	}
	else {
		bool is_on = false;
		for (const auto &cell : state.at(9)) {
			is_on = is_on || cell;
		}
		if (is_on) {
			return std::list<int>{0};
		}
		else {
			return std::list<int>{};
		}
	}
}
std::list<int> solve(std::vector<std::vector<bool>> &state) {
	for (auto i = 0; i < 1023; ++i) {
		auto copy = state;
		for (auto j = 0; j < 10; ++j) {
			if ((i & (1 << j)) != 0) {
				for (const auto &idx : { j - 1, j, j + 1 }) {
					if (idx >= 0 && idx < 10) {
						copy.at(0).at(idx) = !copy.at(0).at(idx);
					}
				}
				copy.at(1).at(j) = !copy.at(1).at(j);
			}
		}
		auto list = dfs(copy);
		if (list.size() == 9) {
			list.push_front(i);
			return list;
		}
	}
	return std::list<int>{};
}
int main() {
	int n;
	for (std::cin >> n; n > 0; --n) {
		std::vector<std::vector<bool>> state(10, std::vector<bool>(10, false));
		bool input;
		for (auto &line : state) {
			for (auto i = 0; i < 10; ++i) {
				std::cin >> input;
				line.at(i) = input;
			}
		}
		auto res = solve(state);
		for (const auto &line : res) {
			for (auto i = 512; i > 0; i >>= 1) {
				std::cout << static_cast<int>((i & (line)) != 0) << ((i != 1) ? ' ' : '\n');
			}
		}
	}
	return 0;
}