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>

#define MAX 12
#define INFTY 1 << 28

using namespace std;

class CMap{
public:
	int m[MAX][MAX];
	vector< pair<int, int> > vHist;

	CMap(){ memset( m, 0, sizeof(*m) * sizeof(**m) ); }
	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)
			m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;

		vHist.push_back( make_pair( i, j ) );
	}
	bool NoLight() const {
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( m[i][j] ) 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';
		}
	}
	void PrintAns() const {
		int a[MAX][MAX] = {{0,},};
		for( unsigned int i = 0; i < vHist.size(); ++i)
			a[vHist[i].first][vHist[i].second] = 1;

		for(int i = 1; i < MAX - 1; ++i){
			cout << a[i][1];
			for(int j = 2; j < MAX - 1; ++j)
				cout << ' ' << a[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 BFS(CMap &stm, CMap &ret){
	vector< CMap > q;

	q.push_back( stm );

	while( !q.empty() ){
		CMap M = q[0];
		q.erase( q.begin() );

		if( M.NoLight() ){
			ret = M;
			break;
		}

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				CMap add;
				int cnt1 = 0;
				const int di[] = {-1,0,1,0};
				const int dj[] = {0,1,0,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
					if( M.m[i+di[k]][j+dj[k]] ) ++cnt1;

				if( cnt1 >= 3 )
				{
					add = M;
					add.PassParticle( i, j );
					if( q.end() == find( q.begin(), q.end(), add ) )
						q.push_back( add );
				}
			}
		}
	}
}
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];

		BFS( M, Answer );

		Answer.PrintAns();
	}
	return 0;
}

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

int c[10][10];
int f[10][10];
bool s[10][10];
int hanten[2] = { 1,0 };
int dx[5] = { -1,0,0,1,0 }, dy[5] = { 0,-1,1,0,0 };
int main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		memset(s, false, sizeof(s));
		for (int d = 0; d < 10; d++) {
			for (int e = 0; e < 10; e++) {
				scanf("%d",&c[d][e]);
			}
		}
		for (int g = 0; g < 1024; g++) {
			for (int h = 0; h < 10; h++) {
				for (int i = 0; i < 10; i++) {
					f[h][i] = c[h][i];
				}
			}
			for (int h = 0; h < 10; h++) {
				if (g & (1 << h)) {
					s[0][h] = true;
					for (int i = 0; i < 5; i++) {
						int x = dx[i], y = h + dy[i];
						if (x >= 0 && x < 10 && y >= 0 && y < 10) {
							f[x][y] = hanten[f[x][y]];
						}
					}
				}
			}
			for (int h = 1; h < 10; h++) {
				for (int i = 0; i < 10; i++) {
					if (f[h - 1][i]) {
						s[h][i] = true;
						for (int j = 0; j < 5; j++) {
							int x = h+dx[j], y = i + dy[j];
							if (x >= 0 && x < 10 && y >= 0 && y < 10) {
								f[x][y] = hanten[f[x][y]];
							}
						}
					}
				}
			}
			bool K = true;
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (f[i][j])K = false;
				}
			}
			if (K) {
				for (int i = 0; i < 10; i++) {
					for (int j = 0; j < 10; j++) {
						if (j)cout << " ";
						cout << s[i][j];
					}
					cout << endl;
				}
			}
		}
	}
}

C++: #include "bits/stdc++.h"
using namespace std;
int a[10][10],b[10][10],ans[10][10];
int 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 {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;
int N;
int A[10][10],B[10][10],T[10][10];
main()
{
	cin>>N;
	for(;N--;)
	{
		for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>A[i][j];
		for(int i=0;i<1<<10;i++)
		{
			for(int j=0;j<10;j++)for(int k=0;k<10;k++)T[j][k]=A[j][k],B[j][k]=0;
			for(int j=0;j<10;j++)
			{
				if(i>>j&1)
				{
					B[0][j]=1;
					T[0][j]^=1;
					T[1][j]^=1;
					if(j>0)T[0][j-1]^=1;
					if(j<9)T[0][j+1]^=1;
				}
			}
			for(int j=1;j<10;j++)
			{
				for(int k=0;k<10;k++)
				{
					if(T[j-1][k])
					{
						B[j][k]=1;
						T[j-1][k]^=1;
						T[j][k]^=1;
						if(k>0)T[j][k-1]^=1;
						if(k<9)T[j][k+1]^=1;
						if(j<9)T[j+1][k]^=1;
					}
				}
			}
			bool flag=true;
			for(int j=0;j<10;j++)if(T[9][j])flag=false;
			if(flag)
			{
				for(int j=0;j<10;j++)
				{
					for(int k=0;k<10;k++)cout<<B[j][k]<<(k==9?"\n":" ");
				}
				break;
			}
		}
	}
}