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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int LC[10][10];
int L[10][10]; 
int F[10][10]; 

void init() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            L[i][j] = LC[i][j];
            F[i][j] = 0;
        }
    }
}

void input() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cin >> LC[i][j];
        }
    }
}

void output() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cout << F[i][j];
            if ( j + 1 < 10 ) cout << " ";
        }
        cout << endl;
    }
}

void flip( int r, int c ) {
    F[r][c] = 1;
    L[r][c] = !L[r][c];
    if ( r - 1 >= 0 ) L[r-1][c] = !L[r-1][c];
    if ( r + 1 < 10 ) L[r+1][c] = !L[r+1][c];
    if ( c - 1 >= 0 ) L[r][c-1] = !L[r][c-1];
    if ( c + 1 < 10 ) L[r][c+1] = !L[r][c+1];
}

bool solve( int r ) {
    if ( r >= 10 ) {
        for ( int i = 0; i < 10; ++ i ) {
            if ( L[r-1][i] == 1 ) return false;
        }
        return true;
    }
    if ( r == 0 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            init();
            for ( int j = 0; j < 10; ++ j ) {
                if ( i & ( 1 << j ) ) flip( r, j );
            }
            if ( solve( r + 1 ) ) return true;
        }
        return 0;
    } else if ( r < 10 ) {
        for ( int i = 0; i < 10; ++ i ) {
            if ( L[r-1][i] ) {
                F[r][i] = 1;
                flip( r, i );
            }
        }
        if ( solve( r + 1 ) ) return true;
    }

    return false;
}

int main() {
    int n;
    while ( cin >> n ) {
        for ( int i = 0; i < n; ++ i ) {
            input();
            solve( 0 );
            output();
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int dx[]={-1,0,0,1};
int dy[]={0,0,-1,0};
int main()
{
    int n;
	cin>>n;
	bool fir=true;
	while(n--){
		if(!fir)cout<<endl;
		int panel[10]={};
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				int tmp;
				cin>>tmp;
				panel[i]|=tmp<<j;
			}
		}
		for(int i=0;i<(1<<10);i++){//1??????ans?????????
			int ans[10]={};
			ans[0]=i;
			for(int j=0;j<9;j++){//????????????ans????¨????
				for(int k=0;k<10;k++){//?????????????????°???
					int tmp=0;
					for(int l=0;l<4;l++){
						int nx=k+dx[l],ny=j+dy[l];
						if(0<=nx&&nx<10&&0<=ny&&ny<9)tmp+=(ans[ny]>>nx)&1;
					}
					if((tmp+2-(panel[j]>>k)&1)%2)ans[j+1]|=1<<k;
				}
			}
			int check[10];
			for(int j=0;j<10;j++)check[j]=(panel[9]>>j)&1;
			for(int j=0;j<10;j++){
				check[j]+=(ans[8]>>j)&1;
				if((ans[9]>>j)&1){
					for(int k=-1;k<=1;k++){
						int x=j+k;
						if(0<=x&&x<10)check[x]++;
					}
				}
			}
			for(int j=0;j<10;j++)check[j]=check[j]%2;
			if(check[9]==0){
				for(int y=0;y<10;y++){
					for(int x=0;x<10;x++){
						int tmp=(ans[y]>>x)&1;
						printf(x==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
		fir=false;
	}
    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];
			}
		}
		return;
	}
	if(y==1){
		now[x][y]=0;
		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{
			now[x][y]=0;
			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++){
		memset(fie,0,sizeof(fie));
		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,-1,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;
}

C++: #include<iostream>
using namespace std;
int t[10][10],u[10][10],ans[10][10],n,flg;
int compute();
void dfs(int);
void change(int,int);
int main(){
  cin>>n;
  while(n--){
    flg=0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cin>>t[i][j];
	ans[i][j]=0;
      }
    }
    dfs(0);
  }
  return 0;
}
void dfs(int x){
  if(flg)return;
  if(x==10){

    
    if(compute()){
      flg=1;
      for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	  if(j)cout<<' ';
	  cout<<ans[i][j];
	}
	cout<<endl;
      }
    }
    
    return;
  }

  dfs(x+1);
  ans[0][x]=1;
  dfs(x+1);
  ans[0][x]=0;
}

int compute(){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      u[i][j]=t[i][j];

  for(int i=0;i<10;i++){
    if(ans[0][i])change(0,i);
  }

  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      if(u[i-1][j]){
	ans[i][j]=1;
	change(i,j);
      }
    }
  }
  for(int i=0;i<10;i++){
    if(u[9][i])return 0;
  }
  return 1;
}

void change(int y,int x){
  u[y][x]=!u[y][x];
  if(y>0)u[y-1][x]=!u[y-1][x];
  if(x>0)u[y][x-1]=!u[y][x-1];
  if(y<9)u[y+1][x]=!u[y+1][x];
  if(x<9)u[y][x+1]=!u[y][x+1];
}