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 <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.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){
        for(int roop=0; roop<n; roop++){
            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=0; i<=9; i++){
                        for(int j=1; j<=10; j++){
                            cout<<l[i][j];
                            if(j==10)break;
                            cout<<" ";
                        }
                        cout<<endl;
                    }
                    break;
                    
                }
            }
            //cout<<"============================"<<endl;
            
            

        }
                
    }
}

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

int t[10][10],s[10][10],ans[10][10];
int dx[] = {0,-1,0,1,0};
int dy[] = {-1,0,0,0,1};

bool check(int *used){
	memset(ans,0,sizeof(ans));
	memcpy(s,t,sizeof(t));
	memcpy(ans,used,sizeof(used));

	for(int i=0;i<10;i++){
		if(used[i]){
			for(int j=0;j<5;j++){
				int nx = i + dx[j];
				int ny = dy[j];

				if(nx>=0 && 10>nx && ny>=0 && 10>ny){
					s[ny][nx] = !s[ny][nx];
				}
			}
		}
	}

	for(int i=1;i<10;i++){
		for(int j=0;j<10;j++){
			if(s[i-1][j]){ //ツ湘」ツつェ1ツづ按づァツづ篠必ツつクツ古オツつェツ必ツ要
				ans[i][j] = 1;
				for(int k=0;k<5;k++){
					int nx = j + dx[k];
					int ny = i + dy[k];

					if(nx>=0 && 10>nx && ny>=0 && 10>ny){
						s[ny][nx] = !s[ny][nx];
					}
				}
			}
		}
	}

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

bool solve(int idx,int *used){
	if(idx == 10){
		if(check(used)){
			return true;
		}
		return false;
	}

	if(solve(idx+1,used)) return true;
	used[idx] = 1;
	if(solve(idx+1,used)) return true;
	used[idx] = 0;

	return false;
}

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

	while(n--){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				cin>>t[i][j];
			}
		}

		int used[10];
		memset(used,0,sizeof(used));
		solve(0,used);

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

	return 0;
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<char,int> P;

void flip(int x,int y,int stage[10][10]){
	const int t[][2] = {{0,0},{-1,0},{1,0},{0,1},{0,-1}};
	for(int i=0;i<5;i++){
		int dx = x+t[i][0];
		int dy = y+t[i][1];

		if(dx < 0 || dx >= 10 || dy < 0 || dy >= 10) continue;

		stage[dy][dx]*=-1;
	}
}

bool checkStage(int store[10][10],int x,int y){
	return store[y][x] == -1 ? true : false;
}

bool isClear(int store[10][10]){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			if(store[y][x]==1) return false;
		}
	}

	return true;
}

void writeResult(int result[10][10]){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			printf("%d%s",result[y][x],x==9 ? "\n" : " ");
		}
	}
}

int main(){

	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			int stage[10][10];
			
			for(int y=0;y<10;y++){
				for(int x=0;x<10;x++){
					int num;
					scanf("%d",&num);
					stage[y][x] = (num == 0 ? -1 : 1);
				}
			}
			
			for(int S=0;S<(1 << 10)-1;S++){
				int store[10][10];
				int result[10][10];
				memset(result,0,sizeof(result));
				//memset(store,0,sizeof(store));
				memcpy(store,stage,sizeof(stage));

				for(int j=0;j<10;j++){
					if(S & (1<<j)){
						flip(j,0,store);
						result[0][j]=1;
					}
				}

				for(int y=1;y<10;y++){
					for(int x=0;x<10;x++){
						flip(x,y,store);
						if(!checkStage(store,x,y-1)){
							flip(x,y,store);
							result[y][x] = 0;
						}
						else{
							result[y][x] = 1;
						}
					}
				}

				if(isClear(store)){
					writeResult(result);
					break;
				}
			}

		}
	}
}