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

using namespace std;

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

	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)
			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] == 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';
		}
	}

	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;
	}
};
inline bool inRange(int t, int min, int max){
	return (min <= t && t < max);
}
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[] = {0,-1,0,1,0};
				const int dj[] = {0,0,1,0,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
					if( M.m[i+di[k]][j+dj[k]] == 1 &&
						inRange( i+di[k], 1, MAX - 1) &&
						inRange( j+dj[k], 1, MAX - 1 ) )
						++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<iostream>
#define N 10

using namespace std;

bool dp1[N][N], dp2[N][N];

void reverse(int i, int j){
  if(!(i>=0 && i<N)) return;
  if(!(j>=0 && j<N)) return;
  dp1[i][j] = !dp1[i][j];
}

int main(){
  int n;
  cin >> n;
  for(int k=0; k<n; ++k){
    for(int i=0; i<N; ++i){
      for(int j=0; j<N; ++j){ 
	cin >> dp1[i][j];
	dp2[i][j] = 0;
      }
    }
    for(int i=0; i<N; ++i){
      for(int j=1; j<N; ++j){
	if(dp1[i][j]){
	  dp2[i+1][j] = 1;
	  reverse(i, j);
	  reverse(i+1, j-1);
	  reverse(i+1, j);
	  reverse(i+1, j+1);
	  reverse(i+2, j);
	}
      }
    }
    for(int i=0; i<N; ++i){
      for(int j=0; j<N; ++j){ 
	cout << dp2[i][j];
	if(j != N-1) cout << " ";
      }
      cout << endl;
    }
  }
  return 0;
}

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(a));
		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+=b[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 <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
		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' ); 
		} // end for
	} // end while

	return 0;
}