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 <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD NUM000007
#define EPS 0.0000001
#define NUM 30000
using namespace std;

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= 9 && col >= 0 && col <= 9)return true;
	else{
		return false;
	}
}

int diff_row[5] = {-1,0,0,0,1},diff_col[5] = {0,-1,0,1,0};

int main(){

	int N,table[10][10],work[10][10],calc_row,calc_col;
	bool tmp[10][10],ans[10][10],FLG;
	scanf("%d",&N);

	for(int loop = 0; loop < N; loop++){

		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 10; k++){
				scanf("%d",&table[i][k]);
			}
		}

		for(int i = 0; i < 1024; i++){

			for(int a = 0; a < 10; a++){
				for(int b = 0; b < 10; b++){
					work[a][b] = table[a][b];
				}
			}

			for(int k = 0; k < 10; k++){
				if(i & (1 << k)){
					tmp[0][k] = true;
				}else{
					tmp[0][k] = false;
				}
			}

			for(int a = 0; a < 10; a++){
				if(tmp[0][a]){
					for(int b = 0; b < 5; b++){
						calc_row = 0+diff_row[b];
						calc_col = a+diff_col[b];

						if(rangeCheck(calc_row,calc_col) == true){
							work[calc_row][calc_col] = 1 - work[calc_row][calc_col];
						}
					}
				}
			}

			for(int row = 1; row <= 9; row++){
				for(int col = 0; col <= 9; col++){
					if(work[row-1][col] == 1){
						tmp[row][col] = true;
					}else{
						tmp[row][col] = false;
					}
				}

				for(int a = 0; a <= 9; a++){
					if(tmp[row][a]){
						for(int b = 0; b < 5; b++){
							calc_row = row+diff_row[b];
							calc_col = a+diff_col[b];

							if(rangeCheck(calc_row,calc_col) == true){
								work[calc_row][calc_col] = 1 - work[calc_row][calc_col];
							}
						}
					}
				}

			}

			FLG = true;
			for(int a = 0; a <= 9; a++){
				if(work[9][a] == 1){
					FLG = false;
					break;
				}
			}
			if(FLG){
				for(int a = 0; a < 10; a++){
					for(int b = 0; b < 10; b++)ans[a][b] = tmp[a][b];
				}
				break;
			}

		}

		for(int i = 0; i < 10; i++){
			for(int k = 0; k < 9; k++){
				if(ans[i][k]){
					printf("1 ");
				}else{
					printf("0 ");
				}
			}
			if(ans[i][9]){
				printf("1\n");
			}else{
				printf("0\n");
			}
		}
	}

	return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>


using namespace std;


void f(bool box[12][12]){
    for(int i=1; i<=10; i++){
        for(int j=1; j<=10; j++){
            cout<<box[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}

int main(){
    int n;
    while(cin>>n){
        
        bool box[12][12]={0};
        
        for(int i=1; i<=10; i++){
            for(int j=1; j<=10; j++){
                cin>>box[i][j];
            }
        }
        //cout<<"----------------------"<<endl;
        
        bool box2[12][12]={0};

        for(int i=0; i<(1<<10 - 1); i++){
            memcpy(box2, box, sizeof(box));
            int l[12][12]={0};
            for(int j=1; j<=10; j++){
                l[0][j]= (i>>j)%2;
            }
            
            for(int j=1; j<=10; j++){
                for(int k=1; k<=10; k++){
                    if(l[j-1][k]==1){
                        box2[j][k]=(box2[j][k]+1)%2;
                        box2[j][k+1]=(box2[j][k+1]+1)%2;
                        box2[j][k-1]=(box2[j][k-1]+1)%2;
                        box2[j-1][k]=(box2[j-1][k]+1)%2;
                        box2[j+1][k]=(box2[j+1][k]+1)%2;
                    }
                }
                
                for(int k=1; k<=10; k++){
                    l[j][k]=box2[j][k];
                }
            }
            
            bool end_flag=true;
            for(int i=1; i<=10; i++){
                if(l[10][i]==1){
                    end_flag=false;
                    break;
                }
            }
            
            
            if(end_flag){
                for(int i=1; i<=10; i++){
                    for(int j=1; j<=10; j++){
                        cout<<l[i][j];
                        if(j==10)break;
                        cout<<" ";
                    }
                    cout<<endl;
                }
                break;
            }
        }
        //cout<<"============================"<<endl;

        
        
    }
}