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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int p[][12],int q[][12],int x){
  int i,j;
  int r[12][12],s[12][12];
  if(x==11){
    for(i=2;i<10;i++){
      for(j=1;j<11;j++){
	if(p[j][i]){
	  p[j  ][i  ]=(p[j  ][i  ]+1)%2;
	  p[j-1][i+1]=(p[j-1][i+1]+1)%2;
	  p[j  ][i+1]=(p[j  ][i+1]+1)%2;
	  p[j+1][i+1]=(p[j+1][i+1]+1)%2;
	  p[j  ][i+2]=(p[j  ][i+2]+1)%2;
	  q[j][i+1]=1;
	}
      }
    }
    for(i=1;i<11;i++){
      if(p[i][10])
	break;
    }
    if(i==11){
      for(i=1;i<11;i++){
	for(j=1;j<10;j++)
	  cout<<q[j][i]<<" ";
	cout<<q[i][j]<<endl;
      }
      return 1;
    }
  }else if(x==10){
    if(p[x][1]){
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }else{
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      if(f(r,s,x+1))
	return 1;
    }
  }else{
      if(p[x][1]){
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x+1][0]=(r[x+1][0]+1)%2;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x+1][1]=(r[x+1][1]+1)%2;
      r[x+2][1]=(r[x+2][1]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      s[x+1][1]=1;
      if(f(r,s,x+1))
	return 1;
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }else{
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      if(f(r,s,x+1))
	return 1;
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x+1][0]=(r[x+1][0]+1)%2;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x+1][1]=(r[x+1][1]+1)%2;
      r[x+2][1]=(r[x+2][1]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      s[x+1][1]=1;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }
  }
  return 0;
}
int main(){
  int i,j,k;
  int q[12][12],r[12][12],n;
  int (*p)[12][12];
  cin>>n;
  p=new int[n][12][12];
  for(i=0;i<n;i++)
    for(j=1;j<11;j++)
      for(k=1;k<11;k++)
	cin>>p[i][k][j];
  for(i=0;i<n;i++){
    memcpy(r,&p[i][0][0],sizeof(r));
    memset(q,0,sizeof(q));
    f(r,q,1);
    memcpy(r,&p[i][0][0],sizeof(r));
    memset(q,0,sizeof(q));
    r[1][0]=(r[1][0]+1)%2;
    r[0][1]=(r[0][1]+1)%2;
    r[1][1]=(r[1][1]+1)%2;
    r[2][1]=(r[2][1]+1)%2;
    r[1][2]=(r[1][2]+1)%2;
    q[1][1]=1;
    f(r,q,1);
  }
  delete [] p;
  return 0;
}

C++: #include <iostream>

using namespace std;

int F[10][10];
int T[10][10];
int P[10];

bool check() {
    for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            if (T[i][j]) return false;
    return true;
}

bool solve(int c, int n) {
    for (int i = 0; i < 10; i++) {
        if (n & (1<<i)) {
            if (c-1 >= 0) T[c-1][i] = !T[c-1][i];
            if (i-1 >= 0) T[c][i-1] = !T[c][i-1];
            T[c][i]   = !T[c][i];
            if (i+1 < 10) T[c][i+1] = !T[c][i+1];
            if (c+1 < 10) T[c+1][i] = !T[c+1][i];
        }
    }
    P[c] = n;
    if (c == 9) return check();
    int next = 0;
    for (int i = 0; i < 10; i++) {
        if (T[c][i]) {
            next |= (1<<i);
        }
    }
    return solve(c+1, next);
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) 
            for (int j = 0; j < 10; j++)
                cin >> F[i][j];
        for (int i = 0; i < (1<<10); i++) {
            for (int k = 0; k < 10; k++) for (int j = 0; j < 10; j++) T[k][j] = F[k][j];
            if (solve(0, i)) 
                break;
        }
        for (int i = 0; i < 10; i++) {
            cout << (P[i] & 1);
            for (int j = 1; j < 10; j++) {
                cout << ' ' << (P[i] & (1<<j) ? 1 : 0);
            }
            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;
set< vector< vector<int> > > S;

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 v[H][W], vector< vector<int> > &u){
  if(end(v)) { ans = u; return ; }
  if(S.find(u) != S.end()) return ;
  S.insert(u);
  REP(i, H){
    REP(j, W){
      if(!next(v, i, j) || u[i][j]) continue;
      rev(v, i, j);
      u[i][j] = 1;
      dfs(v, u);
      u[i][j] = 0;
      rev(v, i, j);
    }
  }
}

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