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>

using namespace std;

int F[10][10];
int T[10][10];
int P[10];

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

bool solve(int c, int n) {
    if (c == 10) return check();
    for (int i = 0; i < 10; i++) {
        if (n & (1<<i)) {
            if (c-1 >= 0) T[c-1][i] = !T[c-1][i];
            if (i-1 >= 0) T[c][i-1] = !T[c][i-1];
            T[c][i]   = !T[c][i];
            if (i+1 < 10) T[c][i+1] = !T[c][i+1];
            if (c+1 < 10) T[c+1][i] = !T[c+1][i];
        }
    }
    P[c] = n;
    int next = 0;
    for (int i = 0; i < 10; i++) {
        if (T[c][i]) {
            next |= (1<<i);
        }
    }
    return solve(c+1, next);
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 10; i++) 
            for (int j = 0; j < 10; j++)
                cin >> F[i][j];
        for (int k = 0; k < 10; k++) for (int j = 0; j < 10; j++) T[k][j] = F[k][j];
        for (int i = 0; i < (1<<10); i++) {
            for (int k = 0; k < 10; k++) for (int j = 0; j < 10; j++) T[k][j] = F[k][j];
            if (solve(0, i)) 
                break;
        }
        for (int i = 0; i < 10; i++) {
            cout << (P[0] & 1);
            for (int j = 1; j < 10; j++) {
                cout << ' ' << (P[i] & (1<<j) ? 1 : 0);
            }
            cout << endl;
        }
    }
    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(x==10){
    if(compute()){
      for(int i=0;i<10;i++){
	for(int j=0;j<10;j++){
	  if(j)cout<<' ';
	  cout<<ans[i][j];
	}
	cout<<endl;
      }
    }
    return;
  }
  ans[0][x]=0;
  dfs(x+1);
  ans[0][x]=1;
  dfs(x+1);
}

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

C++: #include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int a[10][10],b[10][10],m[10][10];

void rev(int x,int y) {
	b[y][x]=1;
	if (x>0) a[y][x-1]=1-a[y][x-1];
	if (x<9) a[y][x+1]=1-a[y][x+1];
	if (y>0) a[y-1][x]=1-a[y-1][x];
	if (y<9) a[y+1][x]=1-a[y+1][x];
	a[y][x]=1-a[y][x];
}

int main() {
	int n,i,j,k;
	cin >> n;
	for (n;n>0;n--) {
		for (i=0;i<10;i++) for (j=0;j<10;j++) cin >> m[i][j];
		for (k=0;k<1024;k++) {
			memset(a,0,sizeof(a)); memset(b,0,sizeof(b));
			for (i=0,j=k;i<10;i++,j/=2)  if (j % 2==1) rev(i,0); 
			for (i=1;i<10;i++) for (j=0;j<10;j++) if (m[i-1][j]!=a[i-1][j]) rev(j,i);
			for (i=0;i<10;i++) if (m[9][i]!=a[9][i]) break;
			if (i==10) break; 
		}
		for (i=0;i<10;i++) {
			cout << b[i][0];
			for (j=1;j<10;j++) cout << ' ' << b[i][j];
			cout << endl;
		}
	}
	return 0;
}

C++: //Name: Doctor's Strange Particles
//Level: 2
//Category: 全探索
//Note: 

/**
 * 一番上の行に対する照射方法を固定すると、それより下の行が全て一意に決まる。
 * したがって、一番上の行だけを全探索してシミュレーションすればよい。
 *
 * オーダーは O(2^W HW)。
 */
#include <iostream>
#include <array>

using namespace std;

array<int,1<<10> eff;

bool solve(bool first) {
    array<int,10> f;
    for(int r = 0; r < 10; ++r) {
        f[r] = 0;
        for(int c = 0; c < 10; ++c) {
            int v;
            cin >> v;
            f[r] |= (v << c);
        }
    }

    array<int,10> ans;
    for(int pat = 0; pat < (1<<10); ++pat) {
        int prev = f[0] ^ pat;
        int pmask = pat;
        ans[0] = pat;
        for(int r = 1; r < 10; ++r) {
            ans[r] = prev;
            const int tmp = f[r] ^ eff[prev] ^ pmask;
            pmask = prev;
            prev = tmp;
        }
        if(prev == 0) break;
    }
    for(int r = 0; r < 10; ++r) {
        for(int c = 0; c < 10; ++c) {
            if(c > 0) cout << ' ';
            cout << !!(ans[r] & (1<<c));
        }
        cout << endl;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(10);

    for(int pat = 0; pat < (1<<10); ++pat) {
        eff[pat] = pat;
        for(int c = 0; c < 10; ++c) {
            if(pat & (1<<c)) {
                if(c > 0) eff[pat] ^= (1<<(c-1));
                if(c < 9) eff[pat] ^= (1<<(c+1));
            }
        }
    }

    bool first = true;
    int N;
    cin >> N;
    while(N-- && solve(first)) {
        first = false;
    }
    return 0;
}

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--){
			if(x != 9)cout << " ";
			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;
}