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>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};

int main(){
  int n;
  cin >> n;
  while(n-- > 0){
    int imap[11][11],syokurin[11][11];
    rep(i,10){
      rep(j,10){
	syokurin[i][j] = 0;
	cin >> imap[i][j];
      }
    }

    rep(i,10){
      rep(j,10){
	if(imap[i][j] == 0)continue;
	syokurin[i][j]++;
	rep(k,4){
	  int nx = j+dx[k],ny = i+dy[k];
	  if(!(0<=nx && nx <10 && 0<=ny && ny <10))continue;
	  syokurin[ny][nx]++;
	}
      }
    }

    rep(i,10){
      rep(j,10){
	if(syokurin[i][j] == 1)cout << 0;
	else syokurin[i][j]%2 == 0?cout << 0:cout << 1;
	if(j!=9)cout << " ";
      }
      cout << endl;
    }
    if(n != 0)cout << endl;

  }
  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--){
			printf("");
			for(int k=9;k>=0;k--)	printf("%s%d",(k==9?"":" "),(bool)(ans[i]&(1<<k)));
			puts("");
		}
	}

	return 0;
}

C++: #include<cstdio>
#include<cstring>

int n;
int fie[13][13];
int now[13][13];
int res[13][13];

void flip(int x,int y){
	fie[x][y]=1-fie[x][y];
	fie[x][y+1]=1-fie[x][y+1];
	fie[x][y-1]=1-fie[x][y-1];
	fie[x+1][y]=1-fie[x+1][y];
	fie[x-1][y]=1-fie[x-1][y];
}

void check(int x,int y){
	if(x==10 && y==10){
		int flag=0;
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)if(fie[j][i]==1)flag=1;
		}
		if(flag==0){
			for(int i=1;i<=10;i++){
				for(int j=1;j<=10;j++)res[j][i]=now[j][i];
			}
		}
		return;
	}
	if(y==1){
		now[x][y]=0;
		if(x<=9)check(x+1,y);
		else check(1,y+1);
		
		flip(x,y);
		now[x][y]=1;
		if(x<=9)check(x+1,y);
		else check(1,y+1);
		flip(x,y);
		
	}else{
		if(fie[x][y-1]==1){
			flip(x,y);
			now[x][y]=1;
			if(x<=9)check(x+1,y);
			else check(1,y+1);
			flip(x,y);
		}else{
			now[x][y]=0;
			if(x<=9)check(x+1,y);
			else check(1,y+1);
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int kkk=0;kkk<n;kkk++){
		memset(fie,0,sizeof(fie));
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)scanf("%d",&fie[j][i]);
		}
		memset(now,0,sizeof(now));
		memset(res,-1,sizeof(res));
		check(1,1);
		for(int i=1;i<=10;i++){
			for(int j=1;j<=10;j++)printf("%d%c",res[j][i],j==10?'\n':' ');
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  while(n--){
    int mp[12][12],ans[12][12];
    for(int i=1;i<=10;i++)for(int j=1;j<=10;j++) cin>>mp[i][j];
    int cp[12][12];
 
    for(int i=0;i<(1<<10);i++){
       
      for(int j=1;j<=10;j++)
    for(int k=1;k<=10;k++)cp[j][k]=mp[j][k],ans[j][k]=0;
      for(int j=0;j<10;j++){
    if(i&(1<<j)){
      cp[1][j+1]=!cp[1][j+1];
      cp[1][j]=!cp[1][j];
      cp[1][j+2]=!cp[1][j+2];
      cp[2][j+1]=!cp[2][j+1];
      ans[1][j+1]=1;
    }
      }
      for(int j=2;j<=10;j++){
    for(int k=1;k<=10;k++){
      if(cp[j-1][k]){
        cp[j-1][k]=!cp[j-1][k];
        cp[j][k]=!cp[j][k];
        cp[j][k-1]=!cp[j][k-1];
        cp[j][k+1]=!cp[j][k+1];
        cp[j+1][k]=!cp[j+1][k];
        ans[j][k]=1;
      }
    }
      }
      int f=0;
      for(int j=1;j<=10;j++)
    for(int k=1;k<=10;k++)
      if(cp[j][k])f=1;
      if(!f)break;
    }
 
    for(int i=1;i<=10;i++){
      for(int j=1;j<=10;j++){
    if(j!=1)cout<<' ';
    cout<<ans[i][j];
      }
      cout<<endl;
    }
  }
  return 0;
}

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

int c[10][10];
int f[10][10];
bool s[10][10];
int hanten[2] = { 1,0 };
int dx[5] = { -1,0,0,1,0 }, dy[5] = { 0,-1,1,0,0 };
int main() {
	int a; cin >> a;
	for (int b = 0; b < a; b++) {
		for (int d = 0; d < 10; d++) {
			for (int e = 0; e < 10; e++) {
				scanf("%d",&c[d][e]);
			}
		}
		for (int g = 0; g < 1024; g++) {
			memset(s, 0, sizeof(s));
			for (int h = 0; h < 10; h++) {
				for (int i = 0; i < 10; i++) {
					f[h][i] = c[h][i];
				}
			}
			for (int h = 0; h < 10; h++) {
				if (g & (1 << h)) {
					s[0][h] = true;
					for (int i = 0; i < 5; i++) {
						int x = dx[i], y = h + dy[i];
						if (x >= 0 && x < 10 && y >= 0 && y < 10) {
							f[x][y] = hanten[f[x][y]];
						}
					}
				}
			}
			for (int h = 1; h < 10; h++) {
				for (int i = 0; i < 10; i++) {
					if (f[h - 1][i]) {
						s[h][i] = true;
						for (int j = 0; j < 5; j++) {
							int x = h+dx[j], y = i + dy[j];
							if (x >= 0 && x < 10 && y >= 0 && y < 10) {
								f[x][y] = hanten[f[x][y]];
							}
						}
					}
				}
			}
			bool K = true;
			for (int i = 0; i < 10; i++) {
				for (int j = 0; j < 10; j++) {
					if (f[i][j])K = false;
				}
			}
			if (K) {
				for (int i = 0; i < 10; i++) {
					for (int j = 0; j < 10; j++) {
						if (j)cout << " ";
						cout << s[i][j];
					}
					cout << endl;
				}
			}
		}
	}
}