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;

struct P{int x,y,z;};

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 << " ";
	else 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<iostream>
using namespace std;
enum{W=10,H=10};

bool clear(bool field[H+2][W+2]){
  bool ok=true;
  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)if(field[i][j])ok=false;
  return ok;
}

int main(){
  int n;
  bool field[H+2][W+2];
  bool dup[H+2][W+2];
  int bit[H+2];
  cin>>n;
  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)cin>>field[i][j];
  for(bit[1]=0; bit[1] < (1<<10); bit[1]++){
    for(int i=2;i<=H;i++)bit[i]=0;
    for(int i=1;i<=H;i++)for(int j=1;j<=W;j++)dup[i][j]=field[i][j];
    for(int j=1;j<=W;j++){
      if(!((bit[1]>>j)&1))continue;
      dup[0][j]^=1;
      dup[0][j-1]^=1;
      dup[0][j+1]^=1;
      dup[0-1][j]^=1;
      dup[0+1][j]^=1;
    }
    for(int i=2;i<=H;i++){
      for(int j=1;j<=W;j++){
        if(dup[i-1][j]){
          bit[i]^=(1<<j);
          dup[i][j]^=1;
          dup[i][j-1]^=1;
          dup[i][j+1]^=1;
          dup[i-1][j]^=1;
          dup[i+1][j]^=1;
        }
      }
    }
    if(clear(dup))break;
  }
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
      if(j!=1)cout<<" ";
      if(bit[i]&(1<<j))cout<<"1";
      else cout<<"0";
    }
    cout<<endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int S3[1024];

int main()
{
	rep (S, 1024 ){
		int stat = 0;
		rep (j, 10 ) if (S & (1<<j) ) {
			stat ^= 1<<j;
			if (j > 0 ) stat ^= 1<<(j-1);
			if (j < 9 ) stat ^= 1<<(j+1);
		} // end rep
		S3[S] = stat;
	} // end rep
	int T; scanf ("%d", &T );
	while (T--){
		int org[10] = {};
		rep (i, 10 ) rep (j, 10 ){
			int tmp; scanf ("%d", &tmp );
			org[i] |= tmp<<j;
		} // end rep
		
		int ans = -1;
		rep (S, 1024 ){
			int grid[10];
			rep (i, 10 ) grid[i] = org[i];
		
			grid[0] ^= S3[S];
			grid[1] ^= S;
			for (int i = 1; i < 10; i++ ){
				int pttn = grid[i-1];
				grid[i-1] = 0;
				grid[i] ^= S3[pttn];
				if (i < 9 ) grid[i+1]^=pttn;
			} // end if
			if (grid[9] == 0 ){
				ans = S; break;
			} // end if
		} // end rep
	
		rep (j, 10 ) printf ("%d%c", !!(ans&(1<<j)), j<9 ? ' ' :'\n' );
		org[0] ^= S3[ans];
		org[1] ^= ans;
		for (int i = 1; i < 10; i++ ){
			int pttn = org[i-1];
			org[i-1] = 0;
			org[i] ^= S3[pttn];
			if (i < 10 ) org[i+1]^=pttn;
			rep (j, 10 ) printf ("%d%c", !!(pttn&(1<<j)), j<9 ? ' ' : '\n' ); 
		} // end for
	} // end while

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int a[10][10],b[10][10];

void rev(int x,int y) {
	b[y][x]=1;
	if (x>0) a[y][x-1]=1-a[y][x-1];
	if (x<10) a[y][x+1]=1-a[y][x+1];
	if (y>0) a[y-1][x]=1-a[y-1][x];
	if (y<10) a[y+1][x]=1-a[y+1][x];
	a[y][x]=1-a[y][x];
}

int main() {
	int n,i,j,k,m[10][10];
	cin >> n;
	for (n;n>0;n--) {
		for (i=0;i<10;i++) for (j=0;j<10;j++) cin >> m[i][j];
		for (k=0;k<1024;k++) {
			memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
			for (i=0,j=k;i<10;i++,j/=2)  if (j % 2==1) rev(i,0); 
			for (i=1;i<10;i++) for (j=0;j<10;j++) if (m[i-1][j]!=a[i-1][j]) rev(j,i);
			for (i=0;i<10;i++) if (m[9][i]!=a[9][i]) break;
			if (i==10) break; 
		}
		for (i=0;i<10;i++) {
			cout << b[i][0];
			for (j=1;j<10;j++) cout << ' ' << b[i][j];
			cout << endl;
		}
	}
	return 0;
}

C++: #include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int S3[1024];
	rep(S,1024){
		int stat=0;
		rep(j,10) if(S&(1<<j)) {
			stat^=1<<j;
			if(j>0) stat^=1<<(j-1);
			if(j<9) stat^=1<<(j+1);
		}
		S3[S]=stat;
	}

	int T; scanf("%d",&T);
	while(T--){
		int org[10]={};
		rep(i,10) rep(j,10) {
			int tmp; scanf("%d",&tmp);
			org[i]|=tmp<<j;
		}

		int ans=-1;
		rep(S,1024){
			int grid[10];
			rep(i,10) grid[i]=org[i];

			grid[0]^=S3[S];
			grid[1]^=S;
			for(int i=1;i<10;i++){
				int pttn=grid[i-1];
				grid[i-1]=0;
				grid[i]^=S3[pttn];
				if(i<9) grid[i+1]^=pttn;
			}

			if(grid[9]==0){ ans=S; break; }
		}
if(ans==-1)while(1);

		rep(j,10) printf("%d%c",!!(ans&(1<<j)),j<9?' ':'\n');
		org[0]^=S3[ans];
		org[1]^=ans;
		for(int i=1;i<10;i++){
			int pttn=org[i-1];
			org[i-1]=0;
			org[i]^=S3[pttn];
			if(i<10) org[i+1]^=pttn;
			rep(j,10) printf("%d%c",!!(pttn&(1<<j)),j<9?' ':'\n');
		}
	}

	return 0;
}