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

const int dx[5] = { -1, 0, 0, 0, 1 };
const int dy[5] = {  0,-1, 0, 1, 0 };
int stage[10][10];
int cnt[10][10];

int Color(int y, int x ){
	int tmp = stage[y][x];
	rep (i, 5 ){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx >= 10 || ny >= 10 || nx < 0 || ny < 0 ) continue;
		tmp += cnt[ny][nx];
	} // end rep

	return tmp%2;
}

int solve(){
	for (int y = 1; y < 10; y++)
		rep (x, 10 )
			if (Color(y-1, x ) ) cnt[y][x]=1;
	rep (i, 10 )
			if (Color(9, i ) ) return -1;

	int ret=0;
	rep (y, 10 ) rep (x, 10 ) ret+=cnt[y][x];

	return ret;
}

int ans[10][10];

void bit_dfs(){

	int res = -1;
	rep (i, 1<<10 ){
		memset (cnt, 0, sizeof (cnt ) );
		rep (j, 10 ) cnt[0][9-j]=(i>>j)&1;
		int t = solve();
		if (t >= 0 && (res < 0 || res > t ) ){
			res = t;
			memcpy (ans, cnt, sizeof(cnt ) );
		} // end if
	} // end rep
}

int main()
{
	int T; scanf("%d", &T );
	while (T--){
		memset (ans, 0, sizeof(ans ) );
		memset (cnt, 0, sizeof(cnt ) );
		memset (stage, 0, sizeof(stage ) );
		rep (y, 10 ) rep (x, 10 ) cin >> stage[y][x];
		bit_dfs();
		rep (y, 10 ) rep (x, 10 ) cout << ans[y][x] << (x < 9 ? ' ' : '\n' );
	} // end while
	return 0;
}

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

bool field[11][11], ans[11][11];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cin >> field[i][j];
      }
    }
    
    for(int y = 0 ; y < 10 ; y++){
      for(int x = 0 ; x < 10 ; x++){
	if(y == 0 && x == 0){
	  if(field[0][0] && field[0][1] && field[1][0] && field[1][1]) ans[0][0] = 1;
	}
	else if(y == 0 && x == 9){
	  if(field[0][9] && field[0][8] && field[1][8] && field[1][9]) ans[0][9] = 1;
	}
	else if(y == 9 && x == 0){
	  if(field[9][0] && field[8][0] && field[8][1] && field[9][1]) ans[9][0] = 1;
	}
	else if(y == 9 && x == 9){
	  if(field[9][9] && field[9][8] && field[8][9] && field[8][8]) ans[9][9] = 1;
	}
	else if(y == 0){
	  if(field[0][x] && field[0][x+1] && field[1][x] && field[0][x-1]) ans[0][x] = 1;
	}
	else if(x == 0){
	  if(field[y][0] && field[y+1][0] && field[y][1] && field[y-1][0]) ans[y][0] = 1;
	}
	else if(field[y][x] && field[y-1][x] && field[y+1][x] && field[y][x-1] && field[y][x+1]){
	  ans[y][x] = 1;
	}
	else if(!field[y][x] && !field[y][x+1] && field[y-1][x] && field[y][x-1] &&
		field[y+1][x] && field[y+1][x+1] && field[y-1][x+1] &&
		field[y][x+2]){
	  ans[y][x] = 1, ans[y][x+1] = 1;
	}
      }
    }

    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cout << ans[i][j];
	if(j != 9) cout << ' ';
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define l(i,n) for(int i=0;i<n;i++)
using namespace std;
bool m[12][12],c[12][12],d[12][12],q;
int main(){int n;cin>>n;l(u,n){l(i,10)l(j,10)cin>>m[i][j];
bool f[10],t[10]={0};for(int p=1;p<=1024;p++){
l(i,10)f[i]=t[i];l(i,10)l(j,10)c[i][j]=m[i][j];l(k,10){l(i,10)
if(f[i]){for(int j=max(0,i-1);j<=min(9,i+1);j++)c[k][j]^=1;c[k+1][i]^=1;}
l(i,10)d[k][i]=f[i];l(i,10)f[i]=c[k][i];}q=0;l(i,10)q|=f[i];
if(!q){l(i,10){l(j,10){if(j)cout<<" ";cout<<d[i][j];}cout<<endl;}
break;}l(i,10)if(p%(int)pow(2,i)==0)t[i]^=1;
}}return 0;}

C++: #include<stdio.h>
int t[10][10];
int s[10][10];
int u[10][10];
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		for(int i=0;i<10;i++)
			for(int j=0;j<10;j++)
				scanf("%d",&t[i][j]);
		for(int i=0;i<(1<<10);i++){
			for(int j=0;j<10;j++)
				for(int k=0;k<10;k++){
					s[j][k]=t[j][k];
					u[j][k]=0;
				}
			for(int j=0;j<10;j++)if(i&(1<<j)){
				s[0][j]=(s[0][j]+1)%2;
				if(j<9)s[0][j+1]=(s[0][j+1]+1)%2;
				if(j)s[0][j-1]=(s[0][j-1]+1)%2;
				s[1][j]=(s[1][j]+1)%2;
				u[0][j]=1;
			}
			for(int j=1;j<10;j++){
				for(int k=0;k<10;k++){
					if(s[j-1][k]%2){
						u[j][k]=1;
						s[j][k]=(s[j][k]+1)%2;
						s[j-1][k]=(s[j-1][k]+1)%2;
						if(k)s[j][k-1]=(s[j][k-1]+1)%2;
						if(k<9)s[j][k+1]=(s[j][k+1]+1)%2;
						if(j<9)s[j+1][k]=(s[j+1][k]+1)%2;
					}
				}
			}
			bool ok=true;
			for(int j=0;j<10;j++)if(s[9][j]%2)ok=false;
			if(!ok)continue;
			else{
				for(int j=0;j<10;j++){
					for(int k=0;k<10;k++){
						if(k)printf(" ");
						printf("%d",u[j][k]);
					}
					printf("\n");
				}
				break;
			}
		}
	}
}

C++: #include<vector>
#include<iostream>

using namespace std;



vector<int> GaussJordanMod2(vector<vector<int> > a){
	int n=a.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			if(a[j][i]){
				a[i].swap(a[j]);
				break;
			}
		}
		for(int j=0;j<n;j++){
			if(i==j||a[j][i]==0)continue;
			for(int k=i;k<n+1;k++){
				a[j][k] = (a[j][k]-a[i][k]+2)%2;
			}
		}
	}
	vector<int> res(n);
	for(int i=0;i<n;i++)res[i]=a[i][n];
	return res;
}


int main(){
	int dy[]={0,1,0,-1,0};
	int dx[]={0,0,1,0,-1};
	int n;
	cin>>n;
	while(n--){
		vector<vector<int> > a(100,vector<int>(101,0));
		for(int i=0;i<100;i++){
			int y=i/10,x=i%10;
			for(int j=0;j<5;j++){
				int ny=y+dy[j],nx=x+dx[j];
				if(0<=ny&&ny<10&&0<=nx&&nx<10){
					a[ny*10+nx][i]=1;
				}
			}
		}
		for(int i=0;i<100;i++){
			int c;
			cin>>c;
			a[i][100]=c;
		}
		vector<int> ans(GaussJordanMod2(a));
		for(int i=0;i<10;i++){
			cout<<ans[i*10];
			for(int j=1;j<10;j++){
				cout<<' '<<ans[i*10+j];
			}
			cout<<endl;
		}
	}
	return 0;
}