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<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={0,0,0,1,-1},dy[]={-1,1,0,0,0};

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

void flip(int x, int y) {
  a[y][x]=1;
  for(int i=0; i<5; i++) {
    b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
  }
}

int main() {

  int n;
  cin>> n;
  while(n--) {
    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cin>> d[i][j];
      }
    }

    for(int i=0; i<1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(d));
      for(int j=0; j<10; j++) {
	if((i>>j) & 1) flip(j, 0);
      }

      for(int j=1; j<10; j++) {
	for(int k=0; k<10; k++) {
	  if(b[j-1][k]) flip(k, j);
	}
      }

      int cnt=0;
      for(int j=0; j<10; j++) {
	if(b[9][j]){
	  cnt++; break;
	}
      }

      if(!cnt) break;
    }

    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cout << a[i][j]<< (j==9 ? "" : " ");
      }
      cout<< endl;
    }
  }
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int dx[]={-1,0,0,1};
int dy[]={0,0,-1,0};
int main()
{
    int n;
	cin>>n;
	bool fir=true;
	while(n--){
		//if(!fir)cout<<endl;
		int panel[10]={};
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				int tmp;
				cin>>tmp;
				panel[i]|=tmp<<j;
			}
		}
		for(int i=0;i<(1<<10);i++){//1??????ans?????????
			int ans[10]={};
			ans[0]=i;
			for(int j=0;j<9;j++){//????????????ans????¨????
				for(int k=0;k<10;k++){//?????????????????°???
					int tmp=0;
					for(int l=0;l<4;l++){
						int nx=k+dx[l],ny=j+dy[l];
						if(0<=nx&&nx<10&&0<=ny&&ny<9)tmp+=(ans[ny]>>nx)&1;
					}
					if((tmp+2-(panel[j]>>k)&1)%2)ans[j+1]|=1<<k;
				}
			}
			int check[10];
			for(int j=0;j<10;j++)check[j]=(panel[9]>>j)&1;
			for(int j=0;j<10;j++){
				check[j]+=(ans[8]>>j)&1;
				if((ans[9]>>j)&1){
					for(int k=-1;k<=1;k++){
						int x=j+k;
						if(0<=x&&x<10)check[x]++;
					}
				}
			}
			for(int j=0;j<10;j++)check[j]=check[j]%2;
			if(check[9]==0){
				for(int y=0;y<10;y++){
					for(int x=0;x<10;x++){
						int tmp=(ans[y]>>x)&1;
						printf(x==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
		fir=false;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int a[10][10], b[10][10], c[10][10];
int dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		rep(i, 10)rep(j, 10)scanf("%d", &a[i][j]);
		rep(i, 1 << 10) {
			rep(j, 10)rep(k, 10)b[j][k] = a[j][k];
			memset(c, 0, sizeof(c));
			rep(j, 10)rep(k, 10) {
				if (!j) {
					if (i >> k & 1)continue;
				}
				else if (!b[j - 1][k])continue;
				c[j][k] = 1; b[j][k] = !b[j][k];
				rep(t, 4) {
					int nx = j + dx[t], ny = k + dy[t];
					if (0 <= nx&&nx < 10 && 0 <= ny&&ny < 10)b[nx][ny] = !b[nx][ny];
				}
			}
			rep(j, 10)rep(k, 10) {
				if (b[j][k])goto g;
			}
			rep(j, 10) {
				rep(k, 10) {
					if (k)printf(" ");
					printf("%d", c[j][k]);
				}
				printf("\n");
			}g:;
		}
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

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

bool solve(vector<vector<int> > state, vector<vector<int> >& ans)
{
  for (int i = 0; i < SIZE; ++i) {
    for (int j = 0; j < SIZE; ++j) {
      if ((i == 0 && ans[i][j]) || (i > 0 && state[i-1][j])) {
	ans[i][j] = 1;
	for (int d = 0; d < 5; ++d) {
	  int xx = j + dx[d];
	  int yy = i + dy[d];
	  if (0 <= xx && xx < SIZE && 0 <= yy && yy < SIZE)
	    state[yy][xx] ^= 1;
	}
      }
    }
  }

  for (int i = 0; i < SIZE; ++i) {
    for (int j = 0; j < SIZE; ++j) {
      if (state[i][j])
	return false;
    }
  }
  return true;
}

int main()
{
  int n;
  while (cin >> n) {
    while (n--) {
      vector<vector<int> > state(SIZE, vector<int>(SIZE));
      for (int i = 0; i < SIZE; ++i) {
	for (int j = 0; j < SIZE; ++j)
	  cin >> state[i][j];
      }

      for (int i = 0; i < (1 << SIZE); ++i) {
	vector<vector<int> > ans(SIZE, vector<int>(SIZE, 0));
	for (int j = 0; j < SIZE; ++j) {
	  if (i & (1 << j))
	    ans[0][j] = 1;
	}
	if (solve(state, ans)) {
	  for (int i = 0; i < SIZE; ++i) {
	    for (int j = 0; j < SIZE-1; ++j) 
	      cout << ans[i][j] << " ";
	    cout << ans[i][SIZE-1] << endl;
	  }
	  break;
	}
      }
    }
  }
  return 0;
}