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<queue>
#include<algorithm>

using namespace std;

int a[10][10],b[10][10],ans[10][10],dx[]={1,0,-1,0,0},dy[]={0,1,0,-1,0};

void init(void){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      b[i][j]=a[i][j];
      ans[i][j]=0;
    }
  }
}

void rev(int x, int y){
  for(int k=0;k<5;k++)
    if( 0<=y+dy[k] && 0<=x+dx[k] && y+dy[k]<10 && x+dx[k]<10)
      b[y+dy[k]][x+dx[k]]=b[y+dy[k]][x+dx[k]]?0:1;
}

int ok(void){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      if(b[i][j])return 0;
  return 1;
}

void solve(int p[]){
  init();

  for(int i=0;i<10;i++)
    if(p[i])rev(i,0);

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

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

void func(int p[], int cnt){
  if(9<cnt)solve(p);
  else {
    p[cnt]=0;
    func(p,cnt+1);
    p[cnt]=1;
    func(p,cnt+1);
  }
}

int main(void){
  int n;

  cin >> n;

  while(n--){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	cin >> a[i][j];

    int p[10]={0};
    func(p,0);
  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;
typedef vector<vector<int> > matrix;

int dy[5] = { -1, 0, 0, 0, 1 };
int dx[5] = { 0, -1, 0, 1, 0 };

void print(matrix& mat) {
	REP(y, 10) {
		REP(x, 10) {
			if (x) cout << " ";
			cout << mat[y][x];
		}
		cout << endl;
	}
}

matrix mk_matrix(int n) {
	matrix mat(n);
	REP(i, n) {
		mat[i] = vector<int>(10, 0);
	}
	return mat;
}

void push(matrix& mat, int y, int x) {
	REP(i, 5) {
		int nx = x + dx[i];
		if (nx < 0 || nx >= 10) continue;
		int ny = y + dy[i];
		if (ny < 0 || ny >= 10) continue;
		mat[ny][nx] ^= 1;
	}
}

void solve(matrix& mat) {
	//?????????????????¨????????????????????????
	REP(i, 1024) {
		matrix mat_tmp = mat;
		matrix pushed = mk_matrix(10);
		int tmp = i;
		REP(j, 10) {
			if (!tmp) break;
			if (tmp & 1) {
				push(mat_tmp, 0, j);
				pushed[0][j] = 1;
				//print(mat_tmp);
			}
			tmp >>= 1;
		}

		FOR(y, 1, 10) {
			REP(x, 10) {
				if (mat_tmp[y - 1][x]) {
					push(mat_tmp, y, x);
					pushed[y][x] = 1;
					//print(mat_tmp);
				}
			}
		}
		//cout << i << endl;
		//print(mat_tmp);
		if (find(mat_tmp[9].begin(), mat_tmp[9].end(), 1) == mat_tmp[9].end()) {
			print(pushed);
			//cout << "solved." << endl;
			return;
		}
	}
}

bool AOJ0131()
{
	matrix mat = mk_matrix(10);
	REP(i, 10) {
		REP(j, 10) {
			cin >> mat[i][j];
		}
	}

	solve(mat);

	return true;
}

int main()
{
	int n;
	cin >> n;
	REP(i, n) AOJ0131();

	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-(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;
}

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

int board[12][12];
int used[12][12];

bool lastCheck(){
	for(int y=0;y<10;y++){
		for(int x=0;x<10;x++){
			if(board[y][x])return false;
		}
	}
	return true;
}

bool canPut(int y, int x){
	int sy = y - 1;
	int ty = y + 1;
	int sx = x - 1;
	int tx = x + 1;
	if(sy < 0 || ty >= 10 || sx < 0 || tx >= 10)return false;
	return true;
}

bool allow(int n){
	for(int i=0;i<n;i++){
		int y = i / 10;
		int x = i % 10;

		if(board[y][x] == 0)continue;

		bool ok = false;
		for(int j=n;j<100;j++){
			int ny = j / 10;
			int nx = j % 10;

			int dy = abs(ny - y);
			int dx = abs(nx - x);

			if(dy >= 2)break;
			if(dy + dx <= 1 && canPut(ny, nx)){
				ok = true;
				break;
			}
		}

		if(!ok)return false;
	}
	return true;
}

int pattern[] = {
    0,1,0,
    1,1,1,
    0,1,0
};

void flip(int y, int x){
	int sy = y - 1;
	int sx = x - 1;
	for(int i=0;i<3;i++)for(int j=0;j<3;j++){
		int ny = sy + i;
		int nx = sx + j;
		if(pattern[i*3+j]){
			board[ny][nx] ^= 1;
		}
	}
}

bool dfs(int n){
	if(n >= 10 * 10){
		return lastCheck();
	}
	if(!allow(n)){
		return false;
	}
	int y = n / 10;
	int x = n % 10;

	if(dfs(n + 1)){
		return true;
	}

	flip(y, x);
	used[y][x] = 1;

	if(dfs(n + 1))return true;
	
	used[y][x] = 0;
	flip(y, x);

	return false;
}

void solve(){
	memset(used, 0, sizeof(used));
	dfs(0);
}
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();
		for(int y=0;y<10;y++){
			for(int x=0;x<10;x++){
				cout << used[y][x] << " ";
			}
			cout << endl;
		}
	}
	return 0;
}