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 <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void flip(vvi& a,int i,int j)
{
	int di[]={-1,0,0,0,1};
	int dj[]={0,-1,0,1,0};
	rep(k,5){
		int ni=i+di[k],nj=j+dj[k];
		if(0<=ni && ni<10 && 0<=nj && nj<10)
			a[ni][nj]^=1;
	}
}

int main()
{
	int tc; cin>>tc;
	while(tc--){
		vvi a(10,vi(10));
		rep(i,10) rep(j,10)
			cin>>a[i][j];
		rep(k,1<<10){
			vvi b=a;
			vvi res(10,vi(10));
			rep(i,10)
				if(k&(1<<i))
					flip(b,0,i);
			repi(i,1,10)
				rep(j,10)
					if(b[i-1][j]){
						flip(b,i,j);
						res[i][j]=1;
					}
			if(count(allof(b[9]),0)==10){
				rep(i,10)
					rep(j,10)
						cout<<res[i][j]<<(j==9?'\n':' ');
				break;
			}
		}
	}
	
	return 0;
}

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

int main() {
	int N;
	cin >> N;

	for(int i = 0; i < N; i++) {
		int in[16][16] = {0};
		int react[3][3] = {{0,1,0},{1,1,1},{0,1,0}};

		/* input */
		for(int j = 0; j < 10; j++) {
			for(int k = 0; k < 10; k++) {
				cin >> in[j + 1][k + 1];
			}
		}

		/* search */
		for(int j = 0; j < 1U << 10; j++) {
			int ans[16][16] = {0};
			int table[16][16] = {0};
			memcpy(table, in, sizeof(in));
			for(int k = 0; k < 10; k++) {
				if(j & (1U << k)) {
					for(int l = 0; l < 3; l++) {
						for(int m = 0; m < 3; m++) {
							table[l][k + m] ^= react[l][m];
						}
					}
					ans[0][k] = 1;
				}
				else
					ans[0][k] = 0;
			}
			for(int k = 1; k < 10; k++) {
				for(int l = 0; l < 10; l++) {
					if(table[k - 1 + 1][l + 1] == 1) {
						for(int m = 0; m < 3; m++)
							for(int n = 0; n < 3; n++)
								table[k + m][l + n] ^= react[m][n];
						ans[k][l] = 1;
					}
					else
						ans[k][l] = 0;
				}
			}
			bool flag = true;
			for(int k = 0; k < 10; k++)
				if(table[10][k + 1]) {
					flag = false;
				}
			if(flag) {
				for(int k = 0; k < 10; k++) {
					for(int l = 0; l < 10; l++) {
						if(l)
							cout << " ";
						cout << ans[k][l];
					}
					cout << endl;
				}
				break;
			}
		}
	}

	return 0;
}

C++: #include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int S3[1024];
	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);
		}
		S3[S]=stat;
	}

	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;
		}

		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<10) grid[i+1]^=pttn;
			}

			if(grid[9]==0){ ans=S; break; }
		}
if(ans==-1)while(1);

		rep(j,10) printf("%d%c",(bool)(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",(bool)(pttn&(1<<j)),j<9?' ':'\n');
		}
	}

	return 0;
}

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

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

int main(){
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		int a[10][10],b[10][10] = {};
		for(int j = 0;j < 10;j++){
			for(int k = 0;k < 10;k++) cin >> a[j][k];
		}
		for(int j = 0;j < 1024;j++){
			int t[10][10];
			for(int k = 0;k < 10;k++){
				for(int l = 0;l < 10;l++){
					t[k][l] = a[k][l];
				}
			}
			for(int k = 0;k < 10;k++){
				if(j >> k & 1){
					for(int l = 0;l < 4;l++){
						int nx = dx[l],ny = k + dy[l];
						if(ny >= 0 && ny < 10){
							t[nx][ny] = (t[nx][ny] + 1) % 2;
						}
					}
				}
			}
			for(int k = 0;k < 9;k++){
				for(int l = 0;l < 10;l++){
					if(t[k][l]){
						b[k + 1][l] = 1;
						for(int n = 0;n < 5;n++){
							int nx = k + 1 + dx[n],ny = l + dy[n];
							if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10){
								t[nx][ny] = (t[nx][ny] + 1) % 2;
							}
						}
					}
				}
			}
			bool flag = true;
			for(int k = 0;k < 10;k++){
				if(t[9][k]) flag = false;
			}
			if(flag){
				for(int k = 0;k < 10;k++){
					for(int l = 0;l < 10;l++) {
						cout << (!l ? "" : " ") << b[k][l];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}