Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)
var (
	table, ans = [12][12]int{}, [12][12]int{}
)

func main() {
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	for i := 0; i < n; i++ {
		for j := 1; j < 11; j++ {
			scanner.Scan()
			input := strings.Split(scanner.Text(), " ")
			tmp := [10]int{}
			for k := range input {
				tmp[k], _ = strconv.Atoi(input[k])
			}
			for l := 1; l < 11; l++ {
				table[j][l] = tmp[l-1]
			}
		}
		check(table, 1, ans)
	}
}

func check(table [12][12]int, i int, ans [12][12]int) {
	if i == 11 {
		solve(table, 2, 1, ans)
		return
	}
	ans[1][i] = 0
	check(table, i+1, ans)
	ans[1][i] = 1
	attack(table, 1, i)
	check(table, i+1, ans)
	attack(table, 1, i)
}

func solve(table [12][12]int, i, j int, ans [12][12]int) {
	if i == 11 {
		flag := true
		for k := 1; k < 11; k++ {
			if table[10][k] == 1 {
				flag = false
				break
			}
		}
		if flag {
			printans(ans)
		}
		return
	}
	if table[i-1][j] == 1 {
		ans[i][j] = 1
		attack(table, i, j)
		if j == 10 {
			solve(table, i+1, 1, ans)
		} else {
			solve(table, i, j+1, ans)
		}
		attack(table, i, j)
		ans[i][j] = 0
	} else {
		ans[i][j] = 0
		if j == 10 {
			solve(table, i+1, 1, ans)
		} else {
			solve(table, i, j+1, ans)
		}
	}
}

func printans(ans [12][12]int) {
	for i := 1; i < 11; i++ {
		for j := 1; j < 11; j++ {
			fmt.Print(ans[i][j])
			if j < 10 {
				fmt.Print(" ")
			}
		}
		fmt.Println()
	}
}

func attack(table [12][12]int, i, j int) {
	table[i][j] = 1 - table[i][j]
	table[i-1][j] = 1 - table[i-1][j]
	table[i+1][j] = 1 - table[i+1][j]
	table[i][j-1] = 1 - table[i][j-1]
	table[i][j+1] = 1 - table[i][j+1]
}

C++: #include <iostream>

#define BOARD_SIZE 10

void init(int a[BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) a[i] = 0;
}

void init(int a[][BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		for (int j=0; j<BOARD_SIZE; j++) a[i][j] = 0;
	}
}

void copy(int a[][BOARD_SIZE], int b[][BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		for (int j=0; j<BOARD_SIZE; j++) a[i][j] = b[i][j];
	}
}

bool next(int a[BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		if (a[i] == 0) { a[i] = 1; return true; }
		a[i] = 0;
	}
	return false;
}

void point(int a[], int board[][BOARD_SIZE], int i, int j)
{
	board[i][j] = 1 - board[i][j];
	if (i>0) board[i-1][j] = 1 - board[i-1][j];
	if (i<BOARD_SIZE-1) board[i+1][j] = 1 - board[i+1][j];
	if (j>0) board[i][j-1] = 1 - board[i][j-1];
	if (j<BOARD_SIZE-1) board[i][j+1] = 1 - board[i][j+1];
}

bool isCorrect(int board[][BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		for (int j=0; j<BOARD_SIZE; j++) {
			if (board[i][j] == 1) return false;
		}
	}
	return true;
}

void show(int a[][BOARD_SIZE])
{
	for (int i=0; i<BOARD_SIZE; i++) {
		std::cout << a[i][0];
		for (int j=1; j<BOARD_SIZE; j++) {
			std::cout << " " << a[i][j];
		}
		std::cout << std::endl;
	}
}

bool check(int a[], int board[][BOARD_SIZE], int ans[][BOARD_SIZE])
{
	for (int j=0; j<BOARD_SIZE; j++) {
		if (a[j] == 1) { point(a, board, 0, j); ans[0][j] = 1; }
	}
	
	for (int i=1; i<BOARD_SIZE; i++) {
		for (int j=0; j<BOARD_SIZE; j++) {
			if (board[i-1][j] == 1) { point(a, board, i, j); ans[i][j] = 1; }
		}
	}
	return isCorrect(board);
}

int main()
{
	int board[BOARD_SIZE][BOARD_SIZE];
	int board_cpy[BOARD_SIZE][BOARD_SIZE];
	int a[BOARD_SIZE];
	int ans[BOARD_SIZE][BOARD_SIZE];
	int n; std::cin >> n;
	for (int k=0; k<n; k++) {
		for (int i=0; i<BOARD_SIZE; i++) {
			for (int j=0; j<BOARD_SIZE; j++) std::cin >> board[i][j];
		}
		init(a);
		do {
			init(ans);
			copy(board_cpy, board);
			if (check(a, board_cpy, ans)) { show(ans); break; }
		} while (next(a));
	}
	
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool field[11][11], ans[11][11];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cin >> field[i][j];
      }
    }
    
    memset(ans, 0, sizeof(ans));
    
    for(int y = 0 ; y < 10 ; y++){
      for(int x = 0 ; x < 10 ; x++){
	if(y == 0 && x == 0){
	  if(field[0][0] && field[0][1] && field[1][0]) ans[0][0] = 1;
	}
	else if(y == 0 && x == 9){
	  if(field[0][9] && field[0][8] && field[1][9]) ans[0][9] = 1;
	}
	else if(y == 9 && x == 0){
	  if(field[9][0] && field[8][0] && field[9][1]) ans[9][0] = 1;
	}
	else if(y == 9 && x == 9){
	  if(field[9][9] && field[9][8] && field[8][9]) ans[9][9] = 1;
	}
	else if(y == 0){
	  if(field[0][x] && field[0][x+1] && field[1][x] && field[0][x-1]) ans[0][x] = 1;
	}
	else if(x == 0){
	  if(field[y][0] && field[y+1][0] && field[y][1] && field[y-1][0]) ans[y][0] = 1;
	}
	else if(y == 9){
	  if(field[9][x] && field[9][x+1] && field[8][x] && field[9][x-1]) ans[9][x] = 1;
	}
	else if(x == 9){
	  if(field[y][9] && field[y+1][9] && field[y][8] && field[y-1][9]) ans[y][0] = 1;
	}
	else if(field[y][x] && field[y-1][x] && field[y+1][x] && field[y][x-1] && field[y][x+1]){
	  ans[y][x] = 1;
	}
	else if(!field[y][x] && !field[y][x+1] && field[y-1][x] && field[y][x-1] &&
		field[y+1][x] && field[y+1][x+1] && field[y-1][x+1] &&
		field[y][x+2]){
	  ans[y][x] = 1, ans[y][x+1] = 1;
	}
	else if(!field[y][x] && !field[y+1][x] && field[y-1][x] && field[y][x-1] &&
		field[y][x+1] && field[y+1][x-1] && field[y+1][x+1] &&
		field[y+2][x]){
	  ans[y][x] = 1, ans[y+1][x] = 1;
	}
      }
    }
    
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cout << ans[i][j];
	if(j != 9) cout << ' ';
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #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 &cell : line) {
				std::cin >> input;
				cell = 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;
}