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 <cstring>

using namespace std;

int state[10][10];
int ans[10][10];

inline bool valid(int i, int j) {
    return 0 <= i && i < 10 && 0 <= j && j < 10;
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if ((i == 0 && (bt>>j) % 10 == 1) || (i != 0 && state[i][j] == 1)) {
                    state[i][j] = 1 - state[i][j];
                    if (valid(i+1, j-1)) state[i+1][j-1] = 1 - state[i+1][j-1];
                    if (valid(i+1, j))   state[i+1][j]   = 1 - state[i+1][j];
                    if (valid(i+1, j+1)) state[i+1][j+1] = 1 - state[i+1][j+1];
                    if (valid(i+2, j))   state[i+2][j]   = 1 - state[i+2][j];
                    ans[i][j] = 1;
                }
            }
        }
        bool ok = true;
        for (int j=0; j<10; ++j) {
            if (state[9][j] == 1) ok = false;
        }
        if (ok) return ;
    }
}

int main() {
    int n;
    cin >> n;
    while (n --) {
        memset(state, 0, sizeof(state));
        memset(ans, 0, sizeof(ans));
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cin >> state[i][j];
            }
        }
        solve();
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int dx[] = {0,1,0,-1,0};
const int dy[] = {0,0,1,0,-1};

int tile[10][10];
int tmp[10][10];
int correct(int x,int y){
	return x < 10 && x >= 0 && y < 10 && y >= 0;
}
int getColor(int x,int y){
	int ret = tile[y][x];
	rep(i,5){
		int sx = x + dx[i] , sy = y + dy[i];
		if(!correct(sx,sy))continue;
		if(tmp[sy][sx])ret++;
	}
	return ret%2;
}

int solve(int upperMost){
	rep(i,10)rep(j,10)tmp[i][j] = 0;
	rep(i,10)tmp[0][10-i-1] = (upperMost>>i) & 1;
	//rep(i,10)cout << tmp[0][i] << endl;
	
	for(int i = 1 ; i < 10 ; i++){
		rep(j,10){
			if(getColor(j,i-1) == 1){
				tmp[i][j] = 1;
			}
		}
	}
	
	rep(i,10)rep(j,10)
		if(getColor(j,i))return 0;
	return 1;
}
int main(){
	int N; cin >> N;
	while(N--){
		rep(i,10)rep(j,10)cin >> tile[i][j];
		rep(bit,1<<10){
			if( solve(bit) ){
				rep(i,10){
					rep(j,10)cout << (j?" ":"") << tmp[i][j];
					cout << endl;
				}
				break;
			}
		}
	}
}

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


  }
  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){
		if(x<=9)check(x+1,y);
		else check(0,y+1);
		
		flip(x,y);
		now[x][y]=1;
		if(x<=9)check(x+1,y);
		else check(0,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(0,y+1);
			flip(x,y);
		}else{
			if(x<=9)check(x+1,y);
			else check(0,y+1);
		}
	}
}

int main(void){
	scanf("%d",&n);
	for(int kkk=0;kkk<n;kkk++){
		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);
		if(res[0][0]==-1)while(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<iostream>
#include<vector>
using namespace std;
typedef vector<bool> VB;
typedef vector<VB> VVB;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

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

void next(VVB& G,int bit)
{
  for(int i=0;i<10;i++)
    G[0][i] = ((bit>>i)&1)?1:0; 
}

void execute(VVB&G,VVB& ans)
{
  ans.resize(11);
  for(int i=1;i<11;i++)
    {
      ans[i].resize(10);
      for(int j=0;j<10;j++)
	ans[i][j] = false;
    }

  for(int i=1;i<11;i++)
    {
      for(int j=0;j<10;j++)
	{
	  if(G[i-1][j])
	    {
	      G[i][j] = !G[i][j];
	      ans[i][j] = true;
	      for(int k=0;k<4;k++)
		{
		  int nx = j + dx[k];
		  int ny = i + dy[k];
		  if(!(0 <= nx && nx < 10 && 0 <= ny && ny <= 10))
		    continue;
		  G[ny][nx] = !G[ny][nx];
		}

	    }
	}
    }

}

int main()
{
  int n;
  cin >> n;
  while(n-- > 0)
    {
      VVB G;
      G.resize(11);
      G[0].resize(10);
      for(int i=1;i<=10;i++)
	{
	  G[i].resize(10);
	  for(int j=0;j<10;j++)
	    {
	      bool b;
	      cin >> b;
	      G[i][j] = b;
	    }
	}


      for(int m=0;m<=(1<<10)-1;m++)
	{
	  VVB pre_G = G;
	  VVB ans;
	  next(G,m);

	  execute(G,ans);

	  if(check(G))
	    {
	      for(int i=1;i<=10;i++)
		{
		  for(int j=0;j<10;j++)
		    {
		      cout << ans[i][j];
		      j == 9?cout << endl:cout << " ";
		    }
		}
	      break;
	    }
	  G = pre_G;
	}


    }
  return 0;
}