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>
using namespace std;

const int all = (1 << 10) - 1;

int board[12][12];
int mask[12];
//int conv[(1<<10)+10];
int save[12];

int makeCurrMask(int curr, int m){
    for(int i=0;i<10;i++){
        if((m >> i) & 1){
            int t = (i == 0) ? (7 >> 1) : (7 << (i - 1));
            curr ^= t;
        }
    }
    return curr & all;
}

int main(){
	/*
	for(int line=0;line<1<<10;++line){
		int m = 0;

		for(int i=0;i<10;++i){
			if((line >> i) & 1){
				m ^= 7 << i;
			}
		}

		conv[line] = (m >> 1) & all;
	}*/

	int n;
	cin >> n;

	for(int t=0;t<n;++t){
		for(int y=0;y<10;++y){
			int m = 0;
			for(int x=0;x<10;++x){
				cin >> board[y][x];
			}
			for(int x=0;x<10;++x){
				m = (m << 1) + board[y][x];
			}
			mask[y] = m;
		}

		for(int line=0;line<1<<10;++line){
			int prev = makeCurrMask(mask[0], line);
			int curr = mask[1] ^ line;

			save[0] = line;

			for(int y=1;y<9;++y){
				int doit = prev;
				int nprev = makeCurrMask(curr, doit);
				int ncurr = mask[y+1] ^ doit;

				prev = nprev;
				curr = ncurr;

				save[y] = doit;
			}

			save[9] = prev;

			if(curr ^ prev){
				continue;
			}

			for(int y=0;y<10;++y){
				int m = save[y];
				for(int x=9;x>=0;--x){
					if(x != 9)cout << " ";
					cout << (((m >> x) & 1) ? 1 : 0);
				}
				cout << endl;
			}

			break;
		}
	}
	return 0;
}

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

bool IsLeft(int m[MAX][MAX]){
	for(int i = 1; i < MAX - 1; ++i){
		for(int j = 1; j < MAX - 1; ++j){
			if( m[i][j] ) return true;
		}
	}
	return false;
}
void PassParticle(int m[MAX][MAX], 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;
	}
}
void PrintMap(int m[MAX][MAX]){
	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';
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D ){
		int pi, pj; /* 1ðÅà½­½]³¹çêéÀW */
		int M[MAX][MAX] = {{0,},};
		int Answer[MAX][MAX] = {{0,},};

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

		while( IsLeft(M) ){
			int max = 0;
			for(int i = 1; i < MAX - 1; ++i){
				for(int j = 1; j < MAX - 1 ; ++j){
					int cnt = 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[i+di[k]][j+dj[k]] ) ++cnt;
					}
					if( cnt > max ){ pi = i; pj = j; max = cnt; }
				}
				
			}
			PassParticle( M, pi, pj );
			Answer[pi][pj] = 1;
		}
		PrintMap( Answer );
	}
	return 0;
}