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

#define MAX 12
#define INV (-1)

using namespace std;

inline bool inRange(int t, int min, int max){
	return (min <= t && t < max);
}

class CMap{
public:
	int m[MAX][MAX];

	CMap()
	{
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void PassParticle(int i, int j)
	{
		const int di[] = {0,-1,0,1,0};
		const int dj[] = {0,0,1,0,-1};

		for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
			if( inRange( i+di[k], 1, MAX - 1 ) && inRange( j + dj[k], 1, MAX - 1 ) )
				m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;
	}

	bool NoLight() const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}

	void Print() const
	{
		for(int i = 1; i < MAX - 1; ++i){
			cout << m[i][1];
			for(int j = 2; j < MAX - 1; ++j)
				cout << ' ' << m[i][j];
			cout << '\n';
		}
	}
	
	bool operator==(const CMap &t) const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( t.m[i][j] != m[i][j] )
					return false;
		return true;
	}
};
void DetermineShootingPoints(CMap &stm, CMap &ans){
	while( !stm.NoLight() ){
		vector< pair<int, int > > vt;
		bool bSCont = true;

		for(int i = 1; i < MAX - 1 && bSCont; ++i){
			for(int j = 1; j < MAX - 1 && bSCont; ++j){
				if( stm.m[i][j] == 1 ){
					
					const int di[][2] = { {0,-1}, {-1,0}, {0,1}, {1,0} };
					const int dj[][2] = { {-1,0}, {0,1}, {1,0}, {0,-1} };

					for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
						bool bCont = true;
						int ti1, tj1, ti2, tj2;

						for(int l = 0; l < sizeof(*di)/sizeof(**di) && bCont; ++l){
							if( stm.m[i+di[k][l]][j+dj[k][l]] != 0 ||
								!inRange(i+di[k][l],1,MAX-1) || !inRange(j+dj[k][l],1,MAX-1) ){
									ti1 = tj1 = ti2 = tj2 = INV;
									bCont = false;
							}else{
								switch( k ){
									case 0: ti1 = i + 1; tj1 = j; ti2 = i; tj2 = j + 1; break;
									case 1: ti1 = i; tj1 = j - 1; ti2 = i + 1; tj2 = j; break;
									case 2: ti1 = i - 1; tj1 = j; ti2 = i; tj2 = j - 1; break;
									case 3: ti1 = i; tj1 = j + 1; ti2 = i - 1; tj2 = j; break;
								}
							}
						}
						if( bCont ){
							if( inRange(ti1,1,MAX-1) && inRange(tj1,1,MAX-1) )
								vt.push_back( make_pair( ti1, tj1 ) );
							if( inRange(ti2,1,MAX-1) && inRange(tj2,1,MAX-1) )
								vt.push_back( make_pair( ti2, tj2 ) );
						}
					}

					
				}
			}
		}
		if( vt.size() > 0 ){
			int ti = INV, tj = INV;
			int max1 = 0;
			double maxEfficient = 0.499;
			
			for(unsigned int t = 0; t < vt.size(); ++t){
				int cnt1 = 0;
				int invCnt = 0;
				const int di[] = {0,-1,0,1,0};
				const int dj[] = {0,0,1,0,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
					if( !inRange(vt[t].first+di[k], 1, MAX-1) || !inRange(vt[t].second+dj[k],1,MAX-1) )
						invCnt++;
					if( stm.m[vt[t].first+di[k]][vt[t].second+dj[k]] == 1 )
						cnt1++;
				}

				if( cnt1 > max1 ){
					if( (double)cnt1 / ( 5 - invCnt ) > maxEfficient ){
						maxEfficient = (double)cnt1 / (5 - invCnt);
						ti = vt[t].first; tj = vt[t].second;
						max1 = cnt1;
					}
				}
			}
			if( ti != INV && tj != INV ){
				// cout << ti << ' ' << tj << '\n';
				stm.PassParticle( ti, tj );
				ans.m[ti][tj] = 1;
				bSCont = false;
			}
		}
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D )
	{
		CMap M;
		CMap Answer;

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

		DetermineShootingPoints( M, Answer );
		Answer.Print();
	}
	return 0;
}

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

bool grid[10][10];

void rev(int y,int x){
  int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>10 || sx>10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  bool ans[10][10];

  cin >> t;
  while(t--){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cin >> grid[i][j];
	tmp[i][j] = grid[i][j];
      }
    }

    for(int i=0;i<(1<<10);i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++)grid[j][k] = tmp[j][k];
      }

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = true;
	}else ans[0][j] = false;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = true;
	  }else ans[j][k] = false;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

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