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 <cstdio>
#include <algorithm>

using namespace std;

void frip(int y, int x, int map[10][10]){
	if(y < 0 || x < 0 || y >= 10 || x >= 10){
		return;
	}else{
		map[y][x] = !map[y][x];
	}
}

void frips(int y, int x, int map[10][10]){
	frip(y - 1, x, map);
	frip(y + 1, x, map);
	frip(y, x, map);
	frip(y, x - 1, map);
	frip(y, x + 1, map);
}

int main(){
	
	int n;
	
	int origin[10][10];
	
	int f_point[10][10];
	
	int map[10][10];
	
	bool checker;
	
	cin >> n;
	
	int N = 10;

	for(int loop = 0; loop < n; loop++){
		
		if(loop != 0){
			printf("\n");
		}
		
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				cin >> origin[i][j];
			}
		}
		
		for(int i = 0; i < (1 << N); i++){
			
			for(int x = 0; x < N; x++){
				for(int y = 0; y < N; y++){
					map[y][x] = origin[y][x];
					f_point[y][x] = 0;
				}
			}
			
			for (int x = 0; x < N; x++){
				if((i & (1 << (N - x - 1))) != 0){
					frips(0, x, map);
					f_point[0][x] = 1;
				}else{
				}
			}
			
			for(int y = 1; y < N; y++){
				for(int x = 0; x < N; x++){
					if(map[y - 1][x]){
						frips(y, x, map);
						f_point[y][x] = 1;
					}
				}
			}
			
			checker = true;
			
			for(int x = 0; x < N; x++){
				if(map[N - 1][x]){
					checker = false;
					break;
				}
			}
			
			if(checker){
				for(int y = 0; y < N; y++){
					for(int x = 0; x < N; x++){
						if(f_point[y][x]){
							printf("1 ");
						}else{
							printf("0 ");
						}
					}
					printf("\n");
				}
			}
		}
	}
	
	return 0;
}

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

using namespace std;

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

const int SIZE = 10;
int tile[SIZE][SIZE];
int flip[SIZE][SIZE];

int get(int x, int y)
{
    int c = tile[x][y];

    for (int d = 0; d < 5; ++d) {
        int x2 = x + dx[d];
        int y2 = y + dy[d];

        if (0 <= x2 && x2 < SIZE && 0 <= y2 && y2 < SIZE)
            c += flip[x2][y2];
    }

    return c % 2;
}

bool calc()
{
    for (int i = 1; i < SIZE; ++i) 
        for (int j = 0; j < SIZE; j++) 
            if (get(i - 1, j) != 0) 
                flip[i][j] = 1;

    for (int j = 0; j < SIZE; ++j)
        if (get(SIZE - 1, j) != 0)
            return false;

    return true;
}

void solve()
{
    for (int i = 0; i < 1 << SIZE; ++i) {
        memset(flip, 0, sizeof(flip));
        for (int j = 0; j < SIZE; ++j) 
            flip[0][SIZE - j - 1] = i >> j & 1;

        if(calc())
            break;
    }

    for (int i = 0; i < SIZE; ++i)
        for (int j = 0; j < SIZE; ++j) 
            cout << flip[i][j] << ((j == SIZE - 1) ? '\n' : ' ');
}

int main()
{
    int n;
    
    cin >> n;
    while (n--) {
        for (int i = 0; i < SIZE; ++i)
            for (int j = 0; j < SIZE; ++j)
                cin >> tile[i][j];
        solve();
    }

    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)
{
	//cout << "y:" << y << " x:" << x << endl;
	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,1,9)
	{
		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(1,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 <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 temp[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(temp[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(temp[ny][nx] == 1) temp[ny][nx] = 0;
				else temp[ny][nx] = 1;
			}
		}
	}
}
void dfs(int y,int x)
{
	rep(i,10) rep(j,10) temp[i][j] = f[i][j];
	ans.clear();
	REP(i,1,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(temp[i][j] == 1) cnt++;

	if(cnt == 0) return;
	else
	{
		if(y == 9 && x == 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));
		memset(temp,0,sizeof(temp));

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

		dfs(1,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;
}