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 <cstring>
#include <cmath>
using namespace std;

int board[12][12];
int used[12];
int mask[12];
int all = (1 << 10) - 1;

int makeCurrMask(int curr, int m){
	for(int i=0;i<10;i++){
		if((m >> i) & 1){
			int t = (i == 0) ? (7 >> 1) : (7 << (i - 1));
			curr ^= t;
		}
	}
	return curr & all;
}

bool dfs(int prev, int curr, int index){
	if(index >= 10){
		if(prev)return false;
		return true;
	}
	for(int m=0;m<(1<<10);m++){
		if(index > 0 && prev ^ m)continue;
		int ncurr = makeCurrMask(curr, m);
		int next = mask[index+1] ^ m;

		used[index] = m;
		if(dfs(ncurr, next, index + 1)){
			return true;
		}
	}
	return false;
}

void solve(){
	memset(mask, 0, sizeof(mask));
	memset(used, 0, sizeof(used));
	for(int y=0;y<10;y++){
		int m = 0;
		for(int x=0;x<10;x++){
			m = ((m << 1) + board[y][x]);
		}
		mask[y] = m;
	}
	dfs(-1, mask[0], 0);
}

void output(){
	for(int y=0;y<10;y++){
		int m = used[y];
		for(int x=9;x>=0;x--){
			cout << (((m >> x) & 1) ? 1 : 0) << " ";
		}
		cout << endl;
	}
}

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

	for(int t=0;t<n;t++){
		for(int y=0;y<10;y++){
			for(int x=0;x<10;x++)cin >> board[y][x];
		}
		solve();
		output();
	}
	return 0;
}

C++: #include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int a[10][10],b[10][10],c[10][10],TEST;
int dx[]={0,0,0,1,-1};
int dy[]={0,1,-1,0,0};
bool solve(int x){
  r(i,10)if((x>>i)&1){
    c[0][i]=1;
    r(j,5){
      int y=dy[j];
      int x=dx[j]+i;
      if(y<0||x<0||y>9||x>9)continue;
      b[y][x]=(b[y][x]+1)%2;
    }
  }
  for(int i=0;i<9;i++){
    r(j,10){
      if(b[i][j]){
        c[i+1][j]=1;
        r(k,5){
          int y=i+dy[k]+1;
          int x=j+dx[k];
          if(y<0||x<0||y>9||x>9)continue;
          b[y][x]=(b[y][x]+1)%2;
        }
      }
    }
  }
  r(i,10)r(j,10)if(b[i][j])return 0;
  return 1;
}
int main(){
  cin>>TEST;
  while(TEST--){
    r(i,10)r(j,10)cin>>a[i][j];
    for(int i=0;i<(1<<10);i++){
      r(k,10)r(j,10)b[k][j]=a[k][j];
      memset(c,0,sizeof(c));
      if(solve(i)){
        r(i,10){
          r(j,10){
            if(j)cout<<' ';
            cout<<c[i][j];
          }
          cout<<endl;
        }
        goto L;
      }
    }L:;
  }
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

const int dx[5] = { -1, 0, 0, 0, 1 };
const int dy[5] = {  0,-1, 0, 1, 0 };
int stage[10][10];
int cnt[10][10];

int Color(int y, int x ){
	int tmp = stage[y][x];
	rep (i, 5 ){
		int nx = x + dx[i];
		int ny = y + dy[i];
		if (nx >= 10 || ny >= 10 || nx < 0 || ny < 0 ) continue;
		tmp += cnt[ny][nx];
	} // end rep

	return tmp%2;
}

int solve(){
	for (int y = 1; y < 10; y++)
		rep (x, 10 )
			if (Color(y-1, x ) ) cnt[y][x]=1;
	rep (i, 10 )
			if (Color(9, i ) ) return -1;

	int ret=0;
	rep (y, 10 ) rep (x, 10 ) ret+=cnt[y][x];

	return ret;
}

int ans[10][10];

void bit_dfs(){

	int res = -1;
	rep (i, 1<<10 ){
		memset (cnt, 0, sizeof (cnt ) );
		rep (j, 10 ) cnt[0][j]=(i>>j)&1;
		int t = solve();
		if (t >= 0 && (res < 0 || res > t ) ){
			res = t;
			memcpy (ans, cnt, sizeof(cnt ) );
		} // end if
	} // end rep
}

int main()
{
	int T; scanf("%d", &T );
	while (T--){
		memset (ans, 0, sizeof(ans ) );
		memset (cnt, 0, sizeof(cnt ) );
		memset (stage, 0, sizeof(stage ) );
		rep (y, 10 ) rep (x, 10 ) cin >> stage[y][x];
		bit_dfs();
		rep (y, 10 ) rep (x, 10 ) cout << ans[y][x] << (x < 9 ? ' ' : '\n' );
	} // end while
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;


void mark(int mp[10][10],int y,int x){
  int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||ny<0||nx>=10||ny>=10)continue;
    mp[ny][nx]=!mp[ny][nx];
  }
  mp[y][x]=!mp[y][x];
}

bool check(int mp[10][10]){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)if(mp[i][j])return 0;
  return 1;
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int mp[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>mp[i][j];

    int ans[10][10];
    for(int i=0;i<(1<<10)&&!check(mp);i++){
      for(int j=0;j<10;j++)ans[0][j]=(i&(1<<j)),mark(mp,0,j);
      for(int j=1;j<10;j++)
	for(int k=0;k<10;k++)
	  if((ans[j][k]=mp[j-1][k]))mark(mp,j,k);
    }

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

  }

  return 0;
}