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 <cstring>

using namespace std;

const int dx[] = {0, -1, 0, 1, 0};
const int dy[] = {-1, 0, 0, 0, 1};

int state[10][10];
int ans[10][10];

void pass(int y, int x) {
    for (int i=0; i<5; ++i) {
        if (0 <= y + dy[i] && y + dy[i] < 10 && 0 <= x + dx[i] && x + dx[i] < 10) {
            state[y + dy[i]][x + dx[i]] = 1 - state[y + dy[i]][x + dx[i]];
        }
    }
    ans[y][x] = 1 - ans[y][x];
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int j=0; j<10; ++j) {
            if ((bt>>j) & 1) {
                pass(0, j);
            }
        }
        for (int i=1; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i-1][j] == 1) {
                    pass(i, j);
                }
            }
        }
        bool ok = true;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][j] == 1) ok = false;
            }
        }
        if (ok) return ;
    }
}

int main() {
    int n;
    cin >> n;
    while (n --) {
        memset(state, 0, sizeof(state));
        memset(ans, 0, sizeof(ans));
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cin >> state[i][j];
            }
        }
        solve();
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <string.h>
using namespace std;
int dx[]={-1,0,1,0,0};
int dy[]={0,-1,0,1,0};

int main() {
	int n ; cin >> n ;
	while(n--){
		int field[10][10];
		for(int i=0;i<10;i++) for(int j=0;j<10;j++) cin >> field[i][j];
		int tmp_ans[10][10]={0}; bool failed=false;
		int tmp_field[10][10];
		for(int i=0;i<1<<10;i++){
			memset(tmp_ans,0,sizeof(tmp_ans));
			memcpy(tmp_field,field,sizeof(field));
			for(int j=0;j<10;j++) tmp_ans[0][10-1-j]= i>>j & 1;
			for(int j=0;j<10;j++){
				if(tmp_ans[0][j]){
					for(int m=0;m<=4;m++)
						if(0<=j+dx[m] && j+dx[m]<10 && 0<=dy[m] ) (tmp_field[dy[m]][j+dx[m]])^=1;
				}
			}
			for(int l=1;l<10;l++){
				for(int k=0;k<10;k++){
					if(tmp_field[l-1][k]){
						tmp_ans[l][k]=true;
						for(int m=0;m<=4;m++)
							if(0<=k+dx[m] && k+dx[m]<10 && 0<=l+dy[m] && l+dy[m]<10) tmp_field[l+dy[m]][k+dx[m]]^=1;
					}
				}
			}
			for(int j=0;j<10;j++) if(tmp_field[9][j]) failed=true;
			if(!failed) break;
		}
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++) {if(j) cout << ' ' ; cout << tmp_ans[i][j] ;}
			cout << '\n' ;	
		}
	}
}

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

int n,s,y,x,i;
int 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(i=0; i<5; i++)
	{
		b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
	}
}

int main()
{
	cin >> n;
	while(n--)
	{
		for(y=1; y<=10; y++)
		for(x=1; x<=10; x++)
		{
			cin >> d[y][x];
		}

		for(i=0; i<1024; i++)
		{
			memset(a,0,sizeof(a));
			memcpy(b,d,sizeof(d));

			for(y=1,x=1; x<=10; x++)
			{
				if((i>>(x-1))&1) flip(x,y);
			}

			for(y=2; y<=10; y++)
			for(x=1; x<=10; x++)
			{
				if(b[y-1][x]) flip(x,y);
			}

			for(y=10,x=1,s=0; x<=10; x++)
			{
				s+=b[y][x];
			}

			if(s==0) break;
		}

		for(y=1; y<=10; y++)
		{
			for(x=1; x<=10; x++)
			{
				cout << a[y][x] << (x==10?"":" ");
			}
			cout << endl;
		}
	}
}

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(); }
	
	void Reset(){
		for(int i = 0; i < N+2; ++i){
			for(int j = 0; j < N+2; ++j){
				m[i][j] = 0;
				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(int range = N + 1) const
	{
		for(int i = 1; i < range; ++i)
			for(int j = 1; j < range; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}
	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;
			for(unsigned int bits = 0; bits < B.size() && bCont; ++bits){
				if( B[bits] == true )
					if( !M.PassParticle(1,N-bits,true) )
						break;

				if( DetermineShootingPoints( M ) ){
					bCont = false;
					break;
				}
			}	
		}
		cout << " ----------------------- \n";
		M.PrintAnswer();
	}
	return 0;
}