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<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[12][12];
int f[12][12];
int res[12][12];
int b[20] = {1};
int dh[5] = {0, 0, 0, 1, -1};
int dw[5] = {0, 1, -1, 0, 0};

signed main(void){
  int i, j, k, l;
  rep1(i, 20)b[i] = b[i - 1] << 1;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    for(;n--;){
      rep(i, 10)rep(j, 10)scanf("%d", &a[i + 1][j + 1]);
      rep(k, b[10]){
        rep(i, 12)rep(j, 12){
          f[i][j] = a[i][j];
          res[i][j] = 0;
        }
        for(int x = k, d = 1;x;x /= 2){
          res[1][d++] = x % 2;
          if(x % 2 == 1)rep(l, 5)f[1 + dh[l]][d + dw[l]] ^= 1;
        }

        rep1(i, 10)rep(j, 10)if(f[i][j + 1] == 1){
          res[i + 1][j + 1] = 1;
          rep(l, 5)f[i + 1 + dh[l]][j + 1 + dw[l]] ^= 1;
        }
        bool isok = true;
        rep(i, 10)rep(j, 10)if(f[i + 1][j + 1] == 1)isok = false;
        if(isok){
          rep(i, 10){
            rep(j, 9)printf("%d ", res[i + 1][j + 1]);
            printf("%d\n", res[i + 1][j + 1]);
          }
          break;
        }
      }
    }


/*/

//*/ break;
  }
  return 0;
}

C++: // 最初の一行さえ決め打ちしてしまえば、あとは必然的に決まる
// 全探索2^10 * 9
#include<iostream>
#include<vector>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[5] = {0,0,1,-1,0};
int dj[5] = {1,-1,0,0,0};

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        vector<vector<int>> mat(10, vector<int>(10));
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                cin >> mat[i][j];
            }
        }
        for(int s = 0; s < 1<<10; s++){
            vector<vector<int>> cp = mat, ans(10, vector<int>(10, 0));
            for(int j = 0; j < 10; j++){
                if((s>>j)&1)    continue;
                ans[0][j] = 1;
                for(int k = 0; k < 5; k++){
                    int ni = 0+di[k], nj = j+dj[k];
                    if(inRange(ni,0,10)&&inRange(nj,0,10)){
                        cp[ni][nj] = 1-cp[ni][nj];
                    }
                }
            }
            for(int i = 1; i < 10; i++){
                for(int j = 0; j < 10; j++){
                    if(cp[i-1][j] == 0) continue;
                    ans[i][j] = 1;
                    for(int k = 0; k < 5; k++){
                        int ni = i+di[k], nj = j+dj[k];
                        if(inRange(ni,0,10)&&inRange(nj,0,10)){
                            cp[ni][nj] = 1-cp[ni][nj];
                        }
                    }
                }
            }
            bool valid = true;
            for(int j = 0; j < 10; j++) valid &= !cp[9][j];
            if(valid){
                // answer.
                for(int i = 0; i < 10; i++){
                    for(int j = 0; j < 10; j++){
                        cout << ans[i][j] << " \n"[j==9];
                    }
                }
                break;
            }
        }
    }
    return 0;
}

C++: #include<cstdio>

using namespace std;

int memo[11][1024];

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

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

		for(int i=0;i<1024;i++)	memo[0][i]=0;
		for(int r=1;r<=10;r++){
			for(int i=0;i<1024;i++){
				memo[r][i]=-1;
				for(int b=0;b<1024;b++){
					if(memo[r-1][b]==-1)	continue;
					if((cell[r-1]^memo[r-1][b]^sw[b]^i)==0)	memo[r][i]=b;
				}
			}
		}

		int ans[10];
		for(int i=0,j=memo[10-i][0];i<10;i++,j=memo[10-i][j])	ans[i]=j;
		for(int i=9;i>=0;i--){
			for(int k=9;k>=0;k--)	printf("%s%d",(k==9?"":" "),(bool)(ans[i]&(1<<k)));
			puts("");
		}
	}

	return 0;
}