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<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool mem[12][12],cop[12][12],done[12][12];

int main(){
  int n;cin>>n;
  while(n--){
    lol(i,10)lol(j,10)cin>>mem[i][j];
    bool flag[10],tmp[10];
    for(int p=1;p<=1024;p++){
      lol(i,10)flag[i]=tmp[i];
      lol(i,10)lol(j,10)cop[i][j]=mem[i][j];
      for(int k=0;k<10;k++){
	lol(i,10){
	  if(!flag[i])continue;
	  for(int j=max(0,i-1);j<=min(9,i+1);j++)cop[k][j]^=1;
	  cop[k+1][i]^=1;
	}
	lol(i,10)done[k][i]=flag[i];
	lol(i,10)flag[i]=cop[k][i];
      }
      bool na=false;
      lol(i,10)na|=flag[i];
      if(!na){
	cout<<endl;
	lol(i,10){
	  lol(j,10)cout<<done[i][j]<<" ";
	  cout<<endl;
	}
      }
      for(int i=0;i<10;i++){
	int r=pow(2,i);
	if(p%r==0)tmp[i]^=1;
      }
    }
  }
  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(!canPut(y, x)){
		return dfs(n + 1);
	}

	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));
	if(!dfs(0)){
		while(1);
	}
}
int main()
{
	int n;
	cin >> n;

	for(int t=0;t<n;t++){
		if(t > 0)cout << endl;
		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++){
			if(y > 0)cout << endl;
			for(int x=0;x<10;x++){
				if(x > 0)cout << " ";
				cout << used[y][x];
			}
		}
	}
	return 0;
}

C++: /* bit DP, O(n*2^(2n)) */

#include<cstdio>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int sw[1024];
	rep(S,1024){
		sw[S]=0;
		if(S&1) sw[S]^=3;
		for(int i=1;i<9;i++) if(S&(1<<i)) sw[S]^=(7<<(i-1));
		if(S&512) sw[S]^=768;
	}

	int T; scanf("%d",&T);
	while(T--){
		int cell[10]={};
		rep(i,10){
			cell[i]=0;
			rep(j,10){
				int tmp; scanf("%d",&tmp);
				cell[i]|=(tmp<<(9-j));
			}
		}

		static int dp[11][1024];
		// dp[r][stat] : rsÚÌXCb`ðµûstat(bit\»)Åµ½Æ«ÉAr-1sÚª·×Ä0ÉÈéæ¤Èr-1sÚÌXCb`Ìµû
		rep(S,1024) dp[0][S]=0;
		rep(r,10){
			rep(S,1024){
				dp[r+1][S]=-1;
				rep(B,1024){
					if(dp[r][B]==-1) continue;
					if((cell[r]^dp[r][B]^sw[B]^S)==0) dp[r+1][S]=B;
				}
			}
		}

		int ans[10];
		for(int i=0,S=dp[10-i][0];i<10;i++,S=dp[10-i][S]) ans[i]=S;
		for(int i=9;i>=0;i--){
			rep(k,10) printf("%d%c",!!(ans[i]&(1<<(9-k))),k<9?' ':'\n');
		}
	}

	return 0;
}

C++: #include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
/** Problem0131 : Coctor's Strange Particles **/
// true : 点灯  false : 消灯
bool board[10][10];
int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1};

void flip(int x, int y)
{
	int nx, ny;
	board[x][y] = !board[x][y];
	rep(i, 4) {
		nx = x+dx[i]; ny = y+dy[i];
		if (0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			board[nx][ny] = !board[nx][ny];
	}
}

int main()
{
	int n;
	bool stamp[10][10];
	bool copy[10][10];
	cin >> n;
	while (n-- > 0) {
		rep(j,10) rep(k,10) {
			int c;
			cin >> c;
			board[k][j] = c==1;
			copy[k][j] = board[k][j];
		}
		
		/** Lights-Out Game Mode
		while (1) {
			int x, y;
			cin >> x >> y;
			flip(x, y);
			
			rep(y, 10) {
				if (board[0][y])
					cout << '1';
				else
					cout  << '0';
				REP(x, 1, 10) {
					if (board[x][y])
						cout << ' ' << '1';
					else
						cout << ' ' << '0';
				}
				cout << endl;
			}
		} **/
		
		
		for (int i=0; i<1024; i++) {
			rep(y, 10) rep(x, 10) board[x][y] = copy[x][y];
		
			rep(j, 10) {
				stamp[j][0] = (i>>j&1);
			}
			rep(j, 10) {
				if (stamp[j][0])
					flip(j, 0);
			}
			
			for (int y=1; y<10; y++) {
				for (int x=0; x<10; x++) {
					if (board[x][y-1]) {
						stamp[x][y] = true;
						flip(x, y);
					} else {
						stamp[x][y] = false;
					}
				}
			}
			
			bool flag=true;
			rep(j, 10) {
				if (board[j][9]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				rep(y, 10) {
					if (stamp[0][y])
						cout << '1';
					else
						cout << '0';
					
					REP(x, 1, 10) {
						if (stamp[x][y])
							cout << ' ' << '1';
						else
							cout << ' ' << '0';
					}
					cout << endl;
				}
				break;
			}
		}
	}
	return 0;
}