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 <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool field[11][11], ans[11][11];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cin >> field[i][j];
      }
    }
    
    memset(ans, 0, sizeof(ans));
    
    for(int y = 0 ; y < 10 ; y++){
      for(int x = 0 ; x < 10 ; x++){
	if(y == 0 && x == 0){
	  if(field[0][0] && field[0][1] && field[1][0] && field[1][1]) ans[0][0] = 1;
	}
	else if(y == 0 && x == 9){
	  if(field[0][9] && field[0][8] && field[1][8] && field[1][9]) ans[0][9] = 1;
	}
	else if(y == 9 && x == 0){
	  if(field[9][0] && field[8][0] && field[8][1] && field[9][1]) ans[9][0] = 1;
	}
	else if(y == 9 && x == 9){
	  if(field[9][9] && field[9][8] && field[8][9] && field[8][8]) ans[9][9] = 1;
	}
	else if(y == 0){
	  if(field[0][x] && field[0][x+1] && field[1][x] && field[0][x-1]) ans[0][x] = 1;
	}
	else if(x == 0){
	  if(field[y][0] && field[y+1][0] && field[y][1] && field[y-1][0]) ans[y][0] = 1;
	}
	else if(y == 9){
	  if(field[9][x] && field[9][x+1] && field[8][x] && field[9][x-1]) ans[9][x] = 1;
	}
	else if(x == 9){
	  if(field[y][9] && field[y+1][9] && field[y][8] && field[y-1][9]) ans[y][0] = 1;
	}
	else if(field[y][x] && field[y-1][x] && field[y+1][x] && field[y][x-1] && field[y][x+1]){
	  ans[y][x] = 1;
	}
	else if(!field[y][x] && !field[y][x+1] && field[y-1][x] && field[y][x-1] &&
		field[y+1][x] && field[y+1][x+1] && field[y-1][x+1] &&
		field[y][x+2]){
	  ans[y][x] = 1, ans[y][x+1] = 1;
	}
	else if(!field[y][x] && !field[y+1][x] && field[y-1][x] && field[y][x-1] &&
		field[y][x+1] && field[y+1][x-1] && field[y+1][x+1] &&
		field[y+2][x]){
	  ans[y][x] = 1, ans[y+1][x] = 1;
	}
      }
    }
    
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cout << ans[i][j];
	if(j != 9) cout << ' ';
      }
      cout << endl;
    }
  }
  return 0;
}

C++: #include<stdio.h>
#include<string.h>
#define MAX_M 10
#define MAX_N 10

const int dx[5]={-1,0,0,0,1};
const int dy[5]={0,-1,0,1,0};

int M,N,c;
int tile[MAX_M][MAX_N],opt[MAX_M][MAX_N],flip[MAX_M][MAX_N];

int get(int x,int y)
{
	int c=tile[x][y];
	for(int d=0;d<5;d++)
	{
		int x2=x+dx[d],y2=y+dy[d];
		if(0<=x2 && x2<M && 0<=y2 && y2<N)
			c+=flip[x2][y2];
	}
	return c%2;
}

int calc()
{
	for(int i=1;i<M;i++)
		for(int j=0;j<N;j++)
			if(get(i-1,j) !=0)
				flip[i][j]=1;
	for(int j=0;j<N;j++)
		if(get(M-1,j)!=0)
			return -1;
	int res=0;
	for(int i=0;i<M;i++)
		for(int j=0;j<N;j++)
			res+=flip[i][j];
	return res;
}

void solve()
{
	memset(opt,0,sizeof(opt));
	int res=-1;
	for(int i=0;i<1<<N;i++)
	{
		memset(flip,0,sizeof(flip));
		
		for(int j=0;j<N;j++)
			flip[0][N-j-1]=i>>j&1;
		int num=calc();
		if(num>=0)
		{
			res=num;
			memcpy(opt,flip,sizeof(flip));
		}
	}
	for(int i=0;i<M;i++)
		for(int j=0;j<N;j++)
			printf("%d%c",opt[i][j],j+1==N?'\n':' ');
}

int main()
{
	N=10;
	M=10;
	int x;
	scanf("%d",&x);
	for(c=0;c<x;c++)
	{
		for(int i=0;i<M;i++)
			for(int j=0;j<N;j++)
			{
				int t;
				scanf("%d",&t);
				tile[i][j]=t;
			}
		solve();
	}
}