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

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

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

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;
	scanf("%d", &n);

	while(n--){
		for(int y=0;y<10;++y){
			int m = 0, f;
			for(int x=0;x<10;++x){
				scanf("%d", &f);
				m = (m << 1) + f;
			}
			mask[y] = m;
		}

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

			save[0] = line;

			for(int y=1;y<9;++y){
				int doit = prev;
				int nprev = curr ^ conv[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)printf(" ");
					printf("%d", (m >> x) & 1);
				}
				puts("");
			}

			break;
		}
	}
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int flip[10][10];
int f[10][10];
int ans[10][10];
int dx[5]={0,0,0,1,-1};
int dy[5]={0,1,-1,0,0};
int n;
int color(int x,int y)
{
	int res=f[x][y];
	for(int i=0;i<5;i++)
	{
		int nx=x+dx[i],ny=y+dy[i];
		if(nx<0||nx>=10||ny<0||ny>=10)continue;
		res+=flip[nx][ny];
	}
	return res%2;
}
int culc()
{
	for(int i=1;i<10;i++)
	{
		for(int j=0;j<10;j++)
		{
			if(color(i-1,j)==1)flip[i][j]=1;
		}
	}
	for(int i=0;i<10;i++)if(color(9,i)==1)return -1;
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int s=0;s<n;s++)
	{
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				cin >> f[i][j];
			}
		}
		for(int i=0;i<(1<<10);i++)
		{
			memset(flip,0,sizeof(flip));
			for(int j=0;j<10;j++)flip[0][j]=(i>>j)&1;
			int num=culc();
			if(num<0)continue;
			else goto end;
		}
		end:;
		for(int i=0;i<10;i++)
		{
			for(int j=0;j<10;j++)
			{
				cout << flip[i][j];
				if(j!=9)cout << ' ';
				else cout << endl;
			}
		}
	}
	return 0;
}