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>
#include<bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a) (0<=(a)&&(a)<10)
int dx[]={-1,0,1,0,0},dy[]={0,0,0,-1,1};
void set(int *a,int b){
	bitset<10> c(b);
	string t=c.to_string<char,char_traits<char>,allocator<char> >();
	rep(i,10)a[i]=t[i]-'0';
}
void change(int t[10][10],int *a,int l){
	rep(i,10){
		rep(d,5){
			if(!ck(l+dy[d])||!ck(i+dx[d]))continue;
			t[l+dy[d]][i+dx[d]]^=a[i];
		}
	}
}
int main(){
	int n; cin>>n;
	while(n--){
		int state[10][10]={0},axion[10][10],temp[10][10];
		rep(i,10)rep(j,10)cin>>state[i][j];
		rep(d,1<<10){
			rep(i,10)rep(j,10)temp[i][j]=state[i][j];
			set(axion[0],d);
			rep(i,10){
				change(temp,axion[i],i);
				if(i<9)rep(j,10)axion[i+1][j]=temp[i][j];
			}
			rep(i,10)rep(j,10)if(temp[i][j])goto NEXT;
			rep(i,10){
				rep(j,10)cout<<axion[i][j]<<(j<9?" ":"");
				cout<<endl;
			}
			goto END;
			NEXT:;
		}
		END:;
	}
	return 0;
}

C++: #include <iostream>
#include <cstring>

using namespace std;

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

C++: #include<iostream>
using namespace std;
int x[12][12];
int T[12][12], V[12][12];
void compute(int X, int Y) {
	int dx[5] = { -1,0,0,0,1 }, dy[5] = { 0,-1,0,1,0 };
	for (int i = 0; i < 5; i++) { T[X + dx[i]][Y + dy[i]]++; T[X + dx[i]][Y + dy[i]] %= 2; }
}
int main() {
	int n; cin >> n;
	for (int h = 0; h < n; h++) {
		for (int i = 1; i <= 10; i++) {
			for (int j = 1; j <= 10; j++)cin >> x[i][j];
		}

		for (int i = 0; i < (1 << 10); i++) {
			int bit[11]; for (int j = 0; j < 10; j++)bit[j + 1] = (i / (1 << j)) % 2;
			for (int j = 0; j < 12; j++) {
				for (int k = 0; k < 12; k++) { T[j][k] = 0; V[j][k] = 0; }
			}

			for (int j = 1; j <= 10; j++) {
				if (bit[j] == 1) {
					compute(1, j);
					V[1][j] = 1;
				}
			}
			for (int j = 2; j <= 10; j++) {
				for (int k = 1; k <= 10; k++) {
					if (T[j - 1][k] != x[j - 1][k]) {
						compute(j, k);
						V[j][k] = 1;
					}
				}
			}
			bool OK = true; for (int k = 1; k <= 10; k++) { if (T[10][k] != x[10][k])OK = false; }
			if (OK == true) {
				for (int j = 1; j <= 10; j++) {
					for (int k = 1; k <= 10; k++) {
						if (k >= 2)cout << ' '; cout << V[j][k];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

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

int board[12][12];
int used[12][12];

bool lastCheck(){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			if(board[y][x])return false;
		}
	}
	return true;
}

bool canPut(int y, int x){
	int sy = y - 1;
	int ty = y + 1;
	int sx = x - 1;
	int tx = x + 1;
	if(sy < 0 || ty >= 10 || sx < 0 || tx >= 10)return false;
	return true;
}

bool allow(int n){
	for(int i=0;i<n;i++){
		int y = i / 10;
		int x = i % 10;

		if(board[y][x] == 0)continue;

		bool ok = false;
		for(int j=n;j<100;j++){
			int ny = j / 10;
			int nx = j % 10;

			int dy = abs(ny - y);
			int dx = abs(nx - x);

			if(dy >= 2)break;
			if(dy + dx <= 1 && canPut(ny, nx)){
				ok = true;
				break;
			}
		}

		if(!ok)return false;
	}
	return true;
}

int pattern[] = {
    0,1,0,
    1,1,1,
    0,1,0
};

void flip(int y, int x){
	int sy = y - 1;
	int sx = x - 1;
	for(int i=0;i<3;i++)for(int j=0;j<3;j++){
		int ny = sy + i;
		int nx = sx + j;
		if(pattern[i*3+j]){
			board[ny][nx] ^= 1;
		}
	}
}

bool dfs(int n){
	if(n >= 10 * 10){
		return lastCheck();
	}
	if(!allow(n)){
		return false;
	}
	int y = n / 10;
	int x = n % 10;

	if(dfs(n + 1)){
		return true;
	}

	flip(y, x);
	used[y][x] = 1;

	if(dfs(n + 1))return true;
	
	used[y][x] = 0;
	flip(y, x);

	return false;
}

void solve(){
	memset(used, 0, sizeof(used));
	dfs(0);
}
int main()
{
	int n;
	cin >> n;

	for(int t=0;t<n;t++){
		for(int y=0;y<10;y++){
			for(int x=0;x<10;x++)cin >> board[y][x];
		}
		solve();
		for(int y=0;y<10;y++){
			for(int x=0;x<10;x++){
				cout << used[y][x] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}

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

int a[10];
int b[10];
int c[10];

int main() {
  int n, t;
  bool solved;
  scanf("%d", &n);
  for (int x=0; x<n; x++) {
    for (int i=0; i<10; i++) a[i] = 0;
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        scanf("%d", &t);
        a[i] |= t<<j;
      }
    }

    solved = false;
    for (int i=0; i<(1<<10); i++) {
      memcpy(b, a, sizeof(a));
      b[0] ^= i;
      b[0] ^= i<<1;
      b[0] ^= i>>1;
      b[0] &= (1<<10)-1;
      b[1] ^= i;
      for (int j=1; j<10; j++) {
        b[j] ^= b[j-1];
        b[j] ^= b[j-1]<<1;
        b[j] ^= b[j-1]>>1;
        b[j] &= (1<<10)-1;
        if (j<9) {
          b[j+1] ^= b[j-1];
        }
      }
      if (!b[9]) {
        c[0] = i;
        for (int j=1; j<10; j++) {
          c[j] = b[j-1];
        }
        solved = true;
        break;
      }
    }

    if (solved) {
      for (int i=0; i<10; i++) {
        for (int j=0; j<10; j++) {
          if (j) putchar(' ');
          printf("%d", (c[i]>>j)&1);
        }
        putchar('\n');
      }
    }
  }

  return 0;
}