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 <bits/stdc++.h>

using namespace std;

int OriginalData[10][10], Ans[10][10], Tmp[10][10];
int Used[10];

bool judge() {
	int dx[] = { 0,-1,0,1,0 };
	int dy[] = { -1,0,0,0,1 };
	int currentX, currentY;

	memset(Ans, 0, sizeof(Ans));
	memcpy(Tmp, OriginalData, sizeof(Tmp));

	for (int j = 0; j < 10; j++) {
		Ans[0][j] = Used[j];
		if (Used[j]) {
			for (int k = 0; k < 5; k++) {
				currentX = dx[k];
				currentY = j + dy[k];

				if (currentX<0 || currentX>9 || currentY<0 || currentY>9) {
					continue;
				}
				Tmp[currentX][currentY] = !Tmp[currentX][currentY];
			}
		}
	}

	for (int i = 1; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (Tmp[i - 1][j]) {
				Ans[i][j] = 1;
				for (int k = 0; k < 5; k++) {
					currentX = i + dx[k];
					currentY = j + dy[k];

					if (currentX<0 || currentX>9 || currentY<0 || currentY>9) {
						continue;
					}
					Tmp[currentX][currentY] = !Tmp[currentX][currentY];
				}
			}
		}
	}

	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			if (Tmp[i][j]) {
				return false;
			}
		}
	}
	return true;
}

bool solve(int col) {
	if (col == 10) {
		if (judge()) {
			return true;
		}
		return false;
	}

	if (solve(col + 1)) {
		return true;
	}
	Used[col] = 1;
	if (solve(col + 1)) {
		return true;
	}
	Used[col] = 0;
	
	return false;
}

int main() {
	int n;

	cin >> n;
	while (n--) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> OriginalData[i][j];
			}
		}
		memset(Used, 0, sizeof(Used));
		solve(0);

		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cout << Ans[i][j] << (j == 9 ? "\n" : " ");
			}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>

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

using namespace std;

int f[10][10];
int dx[5] = {1,0,0,-1,0};
int dy[5] = {0,1,0,0,-1};
vector<pair<int,int> > ans;

void change(int y,int x)
{
	if(f[y-1][x] == 1)
	{
		ans.push_back(make_pair(y,x));
		rep(i,5)
		{
			int ny = y + dy[i];
			int nx = x + dx[i];

			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			{
				if(f[ny][nx] == 1) f[ny][nx] = 0;
				else f[ny][nx] = 1;
			}
		}
	}
}

void dfs(int y,int x)
{
	//cout << "y:" << y << " x:" << x << endl;
	ans.clear();
	rep(i,10)
	{
		rep(j,10)
		{
			if(i == y)
			{
				if(j >= x)
				{
					change(i,j);
				}
			}
			else if(i > y)
			{
				change(i,j);	
			}
		}
	}
	int cnt = 0;
	rep(i,10) rep(j,10) if(f[i][j] == 1) cnt++;

	if(cnt == 0) return;
	else
	{
		if(y == 9)
		{
			return;
		}
		else if(x < 9)
		{
			dfs(y,x+1);
		}
		else if(x == 9)
		{
			dfs(y+1,0);
		}
	}
}

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

	rep(i,n)
	{
		memset(f,0,sizeof(f));

		rep(j,10)
		{
			rep(k,10)
			{
				cin >> f[j][k];
			}
		}
		
		dfs(0,0);

		bool p[10][10];
		rep(j,10) rep(k,10) p[j][k] = false;

		rep(j,ans.size())
		{
			p[ans[j].first][ans[j].second] = true;
		}
	
		rep(j,10)
		{
			rep(k,10)
			{
				if(p[j][k]) cout << 1;
				else cout << 0;

				if(k == 9) cout << endl;
				else cout << " ";
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(){

	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		char field[10][10];
		for(int j = 0; j < 10; j++)
			for(int k = 0; k < 10; k++)
				cin>>field[j][k];


		// ツ催渉可づ可暗ェツ氾板湘」ツづ個づ青づつュツづィツつゥツつヲツつオツ陛サツづーツ個按津ィ
		for(int s = 0; s < (1 << 10); s++){
			char ret[10][10];
			char sit[10][10];
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					sit[j][k]=field[j][k];
				}
			}
			for(int j = 0; j < 10; j++){
				if((s>>j)&1){
					ret[0][j]='1';
					sit[0][j]=((sit[0][j]-'0')^1)+'0';
					if(j-1>=0){
						sit[0][j-1]=((sit[0][j-1]-'0')^1)+'0';
					}
					if(j+1<10){
						sit[0][j+1]=((sit[0][j+1]-'0')^1)+'0';
					}
					sit[1][j]=((sit[1][j]-'0')^1)+'0';
				}
				else{
					ret[0][j]='0';
				}
			}
			// ツ湘」ツづ恵itツづーツ個ゥツづ、ツづ青づつュツづィツ陛板つキツつゥツづつ、ツつゥツづーツ考ツつヲツづゥ
			for(int j = 1; j < 10; j++){
				for(int k = 0; k < 10; k++){
					// ツづ青づつュツづィツつゥツつヲツつキ
					if(sit[j-1][k]=='1'){
						ret[j][k]='1';
						sit[j][k]=((sit[j][k]-'0')^1)+'0';
						if(j-1>=0){
							sit[j-1][k]=((sit[j-1][k]-'0')^1)+'0';
						}
						if(j+1<10){
							sit[j+1][k]=((sit[j+1][k]-'0')^1)+'0';
						}
						if(k-1>=0){
							sit[j][k-1]=((sit[j][k-1]-'0')^1)+'0';
						}
						if(k+1<10){
							sit[j][k+1]=((sit[j][k+1]-'0')^1)+'0';
						}
					}
					else{
						ret[j][k]='0';
					}
				}
			}
			bool ff=false;
			for(int j = 0; j < 10; j++){
				for(int k = 0; k < 10; k++){
					if(sit[j][k]=='1'){
						ff=true;
						break;
					}
				}
				if(ff)
					break;
			}
			if(!ff){
				for(int j = 0; j < 10; j++){
					for(int k = 0; k < 10; k++){
						cout<<ret[j][k];
						if(k==9)
							cout<<endl;
						else
							cout<<" ";
					}
				}
				break;
			}
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>

int n;
int fie[13][13];
int now[13][13];
int res[13][13];

void flip(int x,int y){
	fie[x][y]=1-fie[x][y];
	fie[x][y+1]=1-fie[x][y+1];
	fie[x][y-1]=1-fie[x][y-1];
	fie[x+1][y]=1-fie[x+1][y];
	fie[x-1][y]=1-fie[x-1][y];
}

void check(int x,int y){
	if(x==10 && y==10){
		int flag=0;
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)if(fie[j][i]==1)flag=1;
		}
		if(flag==0){
			for(int i=1;i<=10;i++){
				for(int j=1;j<=10;j++)res[j][i]=now[j][i];
			}
		}
	}
	else if(y==1){
		if(x<=9)check(x+1,y);
		else check(0,y+1);
		
		flip(x,y);
		now[x][y]=1;
		if(x<=9)check(x+1,y);
		else check(0,y+1);
		flip(x,y);
	}else{
		if(fie[x][y-1]==1){
			flip(x,y);
			now[x][y]=1;
			if(x<=9)check(x+1,y);
			else check(0,y+1);
			flip(x,y);
		}else{
			if(x<=9)check(x+1,y);
			else check(0,y+1);
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int kkk=0;kkk<n;kkk++){
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)scanf("%d",&fie[j][i]);
		}
		memset(now,0,sizeof(now));
		memset(res,0,sizeof(res));
		check(1,1);
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)printf("%d%c",res[j][i],j==10?'\n':' ');
		}
	}
	return 0;
}