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<queue>
#include<algorithm>

using namespace std;

int a[10][10],b[10][10],ans[10][10],dx[]={1,0,-1,0,0},dy[]={0,1,0,-1,0};

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

void rev(int x, int y){
  for(int k=0;k<5;k++)
    if( 0<=y+dy[k] && 0<=x+dx[k] && y+dy[k]<10 && x+dx[k]<10)
      b[y+dy[k]][x+dx[k]]=b[y+dy[k]][x+dx[k]]?0:1;
}

int ok(void){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      if(b[i][j])return 0;
  return 1;
}

void solve(int p[]){
  init();

  for(int i=0;i<10;i++)
    if(p[i])rev(i,0);

  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      if(b[i-1][j]){
	rev(j,i);
	ans[i][j]=1;
      }
    }
  }

  if(ok()){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cout << ans[i][j];
	if(j<9)cout << " ";
      }
      cout << endl;
    }
  }
}

void func(int p[], int cnt){
  if(9<cnt)solve(p);
  else {
    p[cnt]=0;
    func(p,cnt+1);
    p[cnt]=1;
    func(p,cnt+1);
  }
}

int main(void){
  int n;

  cin >> n;

  while(n--){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	cin >> a[i][j];

    int p[10]={0};
    func(p,0);
  }

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define f first
#define s second

const int B=10;

main(){
  int n;
  cin>>n;
  while(n--){
    vector< vector<int> > ans(B),tans,ban(B);
    rep(i,B){
      ans[i].resize(B);
      ban[i].resize(B);
    }
    rep(i,B)rep(j,B)cin>>ban[i][j];
    int mina=B*B;
    rep(k,1<<B){
      int tmin=0;
      rep(i,B){
        rep(j,B){
          if(!i)ans[i][j]=!!(1<<j&k);
          else{
            int t=ban[i-1][j]+ans[i-1][j];
            if(j)t+=ans[i-1][j-1];
            if(j+1<B)t+=ans[i-1][j+1];
            if(i>1)t+=ans[i-2][j];
            ans[i][j]=t%2;
          }
          tmin+=ans[i][j];
        }
      }
      rep(i,B){
        rep(j,B){
          int t=ans[i][j]+ban[i][j];
          if(j)t+=ans[i][j-1];
          if(i)t+=ans[i-1][j];
          if(j+1<B)t+=ans[i][j+1];
          if(i+1<B)t+=ans[i+1][j];
        }
      }

      int odd=0;
      rep(j,B){
        int t=ban[B-1][j]+ans[B-1][j]+ans[B-2][j];
        if(j)t+=ans[B-1][j-1];
        if(j+1<B)t+=ans[B-1][j+1];
        odd+=t%2;
      }
      if(!odd && tmin<mina){
        mina=tmin;
        tans=ans;
      }
    }
    rep(i,B){
      rep(j,B){
        if(j)cout<<" ";
        cout<<tans[i][j];
      }
      cout<<endl;
    }
  }
}

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

int n,s,d[12][12],b[12][12],a[12][12];
int dx[] = { 0,0,0,1,-1};
int dy[] = {-1,1,0,0, 0};

void flip(int x, int y)
{
	a[y][x] = 1;
	for(int i=0; i<5; i++)
	{
		b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
	}
}

void func()
{
	for(int i=0; i<=1024; i++)
	{
		memset(a,0,sizeof(d));
		memcpy(b,d,sizeof(d));

		for(int y=1,x=1; x<=10; x++)
		{
			if((i>>(x-1))&1) flip(x,y);
		}

		for(int y=2; y<=10; y++)
		for(int x=1; x<=10; x++)
		{
			if(b[y-1][x]) flip(x,y);
		}

		s=0;
		for(int y=10,x=1; x<=10; x++)
		{
			s+=a[y][x];
		}

		if(s==0) return;
	}
}

int main()
{
	cin >> n;
	while(n--)
	{
		for(int y=1; y<=10; y++)
		for(int x=1; x<=10; x++)
		{
			cin >> d[y][x];
		}

		func();

		for(int y=1; y<=10; y++)
		{
			for(int x=1; x<=10; x++)
			{
				cout << a[y][x] << (x==10?"":" ");
			}
			cout << endl;
		}
	}
}

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[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;
        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;
}