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){
        
        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<<" ";
                    }
                    if(i==9)break;
                    cout<<endl;
                }
                break;
                
            }
        }
        //cout<<"============================"<<endl;

        
        
    }
}

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

int dx[5] = {0,0,0,1,-1};
int dy[5] = {0,1,-1,0,0};
vector<vector<int> > solve(vector<vector<int> > m_){
	vector<vector<int> > ans = m_;
	
	// 0..1023 ツづδ仰ーツプ, iツづ個各ツビツッツトツづ債暗ェツ氾板湘」ツづ個猟アツ子ツづ個督鳴づ陛サツづーツ表ツつキ
	for(int i=0 ; i < 1024 ; i++ ){
		vector<vector<int> > m = m_;
		int d[10][10] = {0};
		
		for(int x=0 ; x < 10 ; x++ ){
			// i ツづ警ツ氾板姪堋づ個ビツッツトツづーツ偲ヲツづィツ出ツつキ
			if( i & (1 << x) ){
				d[0][x] = 1;
				for(int j=0 ; j < 5 ; j++ ){
					int mx = x + dx[j];
					int my = 0 + dy[j];
					if( mx < 0 || my < 0 || mx >= 10 || my >= 10 ) continue;
					m[my][mx] = (m[my][mx])? 0 : 1 ;
				}
			}
		}
		
		for(int y=1 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				if( m[y-1][x] == 1 ){
					d[y][x] = 1;
					for(int j=0 ; j < 5 ; j++ ){
						int mx = x + dx[j];
						int my = y + dy[j];
						if( mx < 0 || my < 0 || mx >= 10 || my >= 10 ) continue;
						m[my][mx] = (m[my][mx])? 0 : 1 ;
					}
				}
			}
		}
		
		bool flag = true;
		for(int y=0 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				if( m[y][x] ){
					flag = false;
					break;
				}
			}
		}
		if( flag ){
			for(int y=0 ; y < 10 ; y++ ){
				for(int x=0 ; x < 10 ; x++ ){
					ans[y][x] = d[y][x];
				}
			}
			break;
		}
	}
	return ans;
}

int main(){
	int n;
	cin >> n;
	for( ; n-- ; ){
		vector<vector<int> > m(10);
		
		for(int y=0 ; y < 10 ; y++ ){
			vector<int> v(10);
			m[y] = v;
			
			for(int x=0 ; x < 10 ; x++ ){
				cin >> m[y][x];
			}
		}
		vector<vector<int> > ans = solve( m );
		for(int y=0 ; y < 10 ; y++ ){
			for(int x=0 ; x < 10 ; x++ ){
				cout << ans[y][x];
				if( x != 9 ) 
					cout << " ";
			}
			cout << endl;
		}
	}
}

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

bool grid[10][10];

void rev(int y,int x){
  int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>=10 || sx>=10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  int ans[10][10];

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

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = 1;
	}else ans[0][j] = 0;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = 1;
	  }else ans[j][k] = 0;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

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