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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main(){
  int n;
  cin >> n;
  
  while(n-- > 0){
    int imap[11][11],syokurin[11][11],solve[11][11];
    rep(i,10){
      rep(j,10){
	syokurin[i][j] = solve[i][j] = 0;
	cin >> imap[i][j];
      }
    }

    while(true)
      {
	rep(i,10){
	  rep(j,10){
	    if(imap[i][j] == 0)continue;
	    syokurin[i][j]++;
	    rep(k,4){
	      int nx = j+dx[k],ny = i+dy[k];
	      if(!(0<=nx && nx <10 && 0<=ny && ny <10))continue;
	      syokurin[ny][nx]++;
	    }
	  }
	}	

	rep(i,10){
	  rep(j,10){
	    if(syokurin[i][j] == 1)continue;
	    if(syokurin[i][j]%2 != 0){
	      solve[i][j] = 1;
	      imap[i][j] = imap[i][j] == 0?1:0;
	      rep(k,4){
		int nx = j+dx[k],ny = i+dy[k];
		if(!(0<=nx && nx <10 && 0<=ny && ny <10))continue;
		imap[ny][nx] = imap[ny][nx]==0?1:0;
	      }
	    }
	  }
	}

	rep(i,10)rep(j,10)syokurin[i][j] = 0;
	bool fin = true;
	rep(i,10)rep(j,10)if(imap[i][j] == 1)fin = false;
	  if(fin)break;
      }

    rep(i,10){
      rep(j,10){
	cout << solve[i][j];
	if(j != 9)cout << " ";
      }
      cout << endl;
    }
    
  }
  return 0;
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int souchi[11][11];
int xx[]={1,-1,0,0,0};
int yy[]={0,0,1,-1,0};

void f(int a,int b){
	int i;
	for(i=0;i<5;i++){
		if(a+xx[i]<0||10<=a+xx[i]||b+yy[i]<0||10<=b+yy[i])continue;
		souchi[a+xx[i]][b+yy[i]]^=1;
	}
}

int main() {
	int n=in();
	int i;
	for(i=0;i<n;i++){
		int a,b;
		int tmp[11][11];
		int res[11][11];
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				cin>>tmp[a][b];
			}
		}
		int bit;
		for(bit=0;bit<1<<10;bit++){
			for(a=0;a<10;a++){
				for(b=0;b<10;b++){
					souchi[a][b]=tmp[a][b];
					res[a][b]=0;
				}
			}
			for(b=0;b<10;b++){
				if(bit>>b&1){
					f(0,b);
					res[0][b]=1;
				}
			}
			for(a=0;a<9;a++){
				for(b=0;b<10;b++){
					if(souchi[a][b]){
						f(a+1,b);
						res[a+1][b]=1;
					}
				}
			}
			bool ok=true;
			for(b=0;b<10;b++){
				if(souchi[9][b])ok=false;
			}
			if(ok){
				for(a=0;a<10;a++){
					for(b=0;b<10;b++){
						cout<<res[a][b];
						if(b!=9)cout<<" ";
					}
					cout<<endl;
				}
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
vvi out(10,vi(10)),in(10,vi(10)),tmp(10,vi(10));
vi top(10);
int dx[]={-1,0,0,0,1};
int dy[]={0,-1,0,1,0};
bool solve2(){
	rep(i,10)rep(j,10)out[i][j]=0;
	tmp=in;
	rep(i,10)if(top[i]){
		out[0][i]=1;
		rep(j,5){
			int nx=dx[j];
			int ny=i+dy[j];
			if(nx>=0&&nx<10&&ny>=0&&ny<10)tmp[nx][ny]=!tmp[nx][ny];
		}
	}
	loop(i,1,10)rep(j,10)if(tmp[i-1][j]){
		out[i][j]=1;
		rep(k,5){
			int nx=i+dx[k];
			int ny=j+dy[k];
			if(nx>=0&&nx<10&&ny>=0&&ny<10)tmp[nx][ny]=!tmp[nx][ny];
		}
	}
	bool h=true;
	rep(i,10)rep(j,10)if(tmp[i][j])h=false;
	return h;
}
bool solve(int a){
	if(a==10)if(solve2())return true;
	else return false;
	
	top[a]=1;
	if(solve(a+1))return true;
	top[a]=0;
	if(solve(a+1))return true;
	return false;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		rep(i,10)top[i]=0;
		rep(i,10)rep(j,10)cin>>in[i][j];
		solve(0);
		rep(i,10){
			rep(j,9)cout<<out[i][j]<<" ";
			cout<<out[i][9]<<endl;
		}
	}
}

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-(panel[j]>>k)&1)ans[j+1]|=1<<k;
				}
			}
			if(ans[9]==0){
				for(int i=0;i<10;i++){
					for(int j=0;j<10;j++){
						int tmp=(ans[i]>>j)&1;
						printf(j==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
		fir=false;
	}
    return 0;
}