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>
using namespace std;

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

int main(){
	int m;
	cin >> m;
	for(int i = 0;i < m;i++){
		int a[10][10],b[10][10] = {};
		for(int j = 0;j < 10;j++){
			for(int k = 0;k < 10;k++) cin >> a[j][k];
		}
		for(int j = 0;j < 1024;j++){
			int t[10][10];
			for(int k = 0;k < 10;k++){
				for(int l = 0;l < 10;l++){
					t[k][l] = a[k][l];
				}
			}
			for(int k = 0;k < 10;k++){
				if((j >> k) & 1){
					b[0][k] = 1;
					for(int l = 0;l < 4;l++){
						int nx = dx[l],ny = k + dy[l];
						if(ny >= 0 && ny < 10){
							t[nx][ny] = (t[nx][ny] + 1) % 2;
						}
					}
				}
			}
			for(int k = 0;k < 9;k++){
				for(int l = 0;l < 10;l++){
					if(t[k][l]){
						b[k + 1][l] = 1;
						for(int n = 0;n < 5;n++){
							int nx = k + 1 + dx[n],ny = l + dy[n];
							if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10){
								t[nx][ny] = (t[nx][ny] + 1) % 2;
							}
						}
					}
				}
			}
			bool flag = true;
			for(int k = 0;k < 10;k++){
				if(t[9][k]) flag = false;
			}
			if(flag){
				for(int k = 0;k < 10;k++){
					for(int l = 0;l < 10;l++) {
						cout << (!l ? "" : " ") << b[k][l];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < j; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define P pair<int, int>
const int H = 10;
const int W = 10;

int my[5] = {1, -1, 0, 0, 0};
int mx[5] = {0, 0, 1, -1, 0};

vector< vector<int> > ans;

bool end(int v[H][W]){
  REP(i, H) REP(j, W) if(v[i][j] == 1) return false;
  return true;
}

bool next(int v[H][W], int y, int x){
  int a = 0, b = 0;
  REP(i, 5){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < H && nx < W){
      if(v[ny][nx]) ++a;
      else ++b;
    }
  }
  return a > b;
}

void rev(int v[H][W], int y, int x){
  REP(i, 5){
    int ny = y + my[i], nx = x + mx[i];
    if(ny >= 0 && nx >= 0 && ny < H && nx < W) v[ny][nx] = (v[ny][nx] + 1) % 2;
  }
}

void dfs(int y, int x, int v[H][W], vector< vector<int> > &u){
  if(end(v)) { ans = u; return ; }
  FOR(i, y, H){
    REP(j, W){
      if(i == y && j <= x) continue;
      if(!next(v, i, j) || u[i][j]) continue;
      rev(v, i, j);
      u[i][j] = 1;
      dfs(i, j, v, u);
      u[i][j] = 0;
      rev(v, i, j);
    }
  }
}

int main() {
  int T; cin >>T;
  REP(t, T){
    ans = vector< vector<int> >();
    int v[H][W];
    REP(i, H) REP(j, W) cin >>v[i][j];
    vector< vector<int> > u(H, vector<int>(W, 0));
    dfs(0, -1, v, u);
    REP(i, H){
      REP(j, W) cout <<ans[i][j] <<(j + 1 == W ? "" : " ");
      cout <<endl;
    }
  }
  return 0;
}