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<cmath>
#include<bitset>
using namespace std;

#define N 10

class CMap{
public:
	int m[N+2][N+2];
	int ans[N+2][N+2];

	CMap(){ Reset(); ResetAnswer(); }
	
	void Reset(){
		for(int i = 0; i < N+2; ++i){
			for(int j = 0; j < N+2; ++j){
				m[i][j] = 0;
			}
		}
	}
	void ResetAnswer(){
		for(int i = 0; i < N+2; ++i){
			for(int j = 0; j < N+2; ++j){
				ans[i][j] = 0;
			}
		}
	}
	bool inline static inRange(int t){
		return ( 1 <= t && t < N + 1 );
	}

	bool PassParticle(int i, int j, bool bConsiderEfficiency = false)
	{
		int cnt0 = 0;
		int cnt1 = 0;
		const int di[] = {0,-1,0,1,0};
		const int dj[] = {0,0,1,0,-1};

		if( bConsiderEfficiency ){
			for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
				if( inRange( i+di[k] ) && inRange( j+dj[k] ) )
					if( m[i+di[k]][j+dj[k]] == 1 ) cnt1++; else cnt0++;
		}

		if( cnt1 < cnt0 )
			return false;

		for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
			if( inRange( i+di[k]) && inRange( j+dj[k]) )
				m[i+di[k]][j+dj[k]] ^= 1;

		ans[ i ][ j ] = 1;
		return true;
	}
	bool NoLight() const
	{
		for(int i = 1; i < N+1; ++i)
			for(int j = 1; j < N+1; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}
	void Print()const{
		for(int i = 1; i < N+1; ++i){
			cout << m[i][1];
			for(int j = 2; j < N+1; ++j)
				cout << ' ' << m[i][j];
			cout << '\n';
		}
	}
	void PrintAnswer() const{
		for(int i = 1; i < N+1; ++i){
			cout << ans[i][1];
			for(int j = 2; j < N+1; ++j)
				cout << ' ' << ans[i][j];
			cout << '\n';
		}
	}
};

bool DetermineShootingPoints(CMap &M){
	for(unsigned int i = 2; i < N+1; ++i){
		for(unsigned int j = 1; j < N+1; ++j){
			if( M.m[i-1][j] == 1 ){
				M.PassParticle( i, j );
			}
		}
	}
	if( M.NoLight() )
		return true;
	else
		return false;
}

int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D )
	{
		bool bCont = true;
		CMap M;
		bitset<N> B;

		for(int i = 1; i < N+1; ++i)
			for(int j = 1; j < N+1; ++j)
				cin >> M.m[i][j];

		for(unsigned long L = 0; L < (unsigned long)pow(2.0,(double)N) && bCont; ++L){
			B = L;
			//cout << L << ": " << B.to_string() << endl;
			CMap Tmp = M;
			for(unsigned int bits = 0; bits < B.size() && bCont; ++bits){
				if( B[bits] )
					M.PassParticle(1,N-bits);//break;
			}
			if( DetermineShootingPoints( M ) ){
				bCont = false;
				break;
			}
			M = Tmp;
		}
		//cout << "END.\n";
		//cout << "CURRENT MAP:\n";
		//M.Print();
		//cout << "ANSWER:\n";
		M.PrintAnswer();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int mp[12][12],ans[12][12];
    for(int i=1;i<=10;i++)for(int j=1;j<=10;j++) cin>>mp[i][j];
    int cp[12][12];

    for(int i=0;i<(1<<10);i++){
      
      for(int j=1;j<=10;j++)
	for(int k=1;k<=10;k++)cp[j][k]=mp[j][k],ans[j][k]=0;
      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  cp[1][j+1]=!cp[1][j+1];
	  cp[1][j]=!cp[1][j];
	  cp[1][j+2]=!cp[1][j+2];
	  cp[2][j+1]=!cp[2][j+1];
	  ans[1][j+1]=1;
	}
      }
      for(int j=2;j<=10;j++){
	for(int k=1;k<=10;k++){
	  if(cp[j-1][k]){
	    cp[j-1][k]=!cp[j-1][k];
	    cp[j][k]=!cp[j][k];
	    cp[j][k-1]=!cp[j][k-1];
	    cp[j][k+1]=!cp[j][k+1];
	    cp[j+1][k]=!cp[j+1][k];
	    ans[j][k]=1;
	  }
	}
      }
      int f=0;
      for(int j=1;j<=10;j++)
	for(int k=1;k<=10;k++)
	  if(cp[j][k])f=1;
      if(!f)break;
    }

    for(int i=1;i<=10;i++){
      for(int j=1;j<=10;j++){
	if(j!=1)cout<<' ';
	cout<<ans[i][j];
      }
      cout<<endl;
    }
  }
  return 0;
}

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++){

    int ny=y+dy[k],nx=x+dx[k];

    if( 0<=ny && 0<=nx && ny<10 && nx<10)
      b[ny][nx]=!b[ny][nx];
  }
}

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);
    ans[0][i]=p[i];
  }
  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 {
    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;
}