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;

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

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 push(int y, int x) {
    for (int i=0; i<5; ++i) {
        if (valid(y + dy[i], x + dx[i])) {
            state[y + dy[i]][x + dx[i]] = 1 - state[y + dy[i]][x + dx[i]];
        }
    }
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int j=0; j<10; ++j) {
            if ((bt>>j) % 10 == 1) {
                push(0, j);
                ans[0][j] = 1 - ans[0][j];
            }
        }
        for (int i=1; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i-1][j] == 1) {
                    push(i, j);
                    ans[i][j] = 1 - ans[i][j];
                }
            }
        }
        bool ok = true;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][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 <vector>
#include <iostream>
using namespace std;
const vector<int> dir = { 0, 1, 0, -1 };
int Q, x;
int main() {
	cin >> Q;
	while (Q--) {
		vector<int> a(10);
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				cin >> x; a[i] |= x << j;
			}
		}
		for (int i = 0; i < 1 << 10; i++) {
			vector<int> b = a, c(10); c[0] = i;
			for (int j = 0; j < 10; j++) {
				if (i & (1 << j)) {
					for (int k = 0; k < 4; k++) {
						int tx = dir[k], ty = j + dir[k ^ 1];
						if (0 <= tx && tx < 10 && 0 <= ty && ty < 10) {
							b[tx] ^= 1 << ty;
						}
					}
					b[0] ^= 1 << j;
				}
			}
			for (int j = 0; j < 9; j++) {
				c[j + 1] = b[j];
				for (int k = 0; k < 10; k++) {
					if (b[j] & (1 << k)) {
						for (int l = 0; l < 4; l++) {
							int tx = j + 1 + dir[l], ty = k + dir[l ^ 1];
							if (0 <= tx && tx < 10 && 0 <= ty && ty < 10) {
								b[tx] ^= 1 << ty;
							}
						}
						b[j + 1] ^= 1 << k;
					}
				}
			}
			if (b[9] == 0) {
				for (int j = 0; j < 10; j++) {
					for (int k = 0; k < 10; k++) {
						if (k) cout << ' ';
						cout << ((c[j] & (1 << k)) ? 1 : 0);
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

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

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

int main(){
	int m;
	cin >> m;
	for(int i = 0;i < m;i++){
		if(m) cout << endl;
		int a[10][10],b[10][10] = {};
		for(int j = 0;j < 10;j++){
			for(int k = 0;k < 10;k++) cin >> a[j][k];
		}
		for(int j = 0;j < 1024;j++){
			int t[10][10];
			for(int k = 0;k < 10;k++){
				for(int l = 0;l < 10;l++){
					t[k][l] = a[k][l];
				}
			}
			for(int k = 0;k < 10;k++){
				if(j >> k & 1){
					for(int l = 0;l < 4;l++){
						int nx = dx[l],ny = k + dy[l];
						if(ny >= 0 && ny < 10){
							t[nx][ny] = (t[nx][ny] + 1) % 2;
						}
					}
				}
			}
			for(int k = 0;k < 9;k++){
				for(int l = 0;l < 10;l++){
					if(t[k][l]){
						b[k + 1][l] = 1;
						for(int n = 0;n < 5;n++){
							int nx = k + 1 + dx[n],ny = l + dy[n];
							if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10){
								t[nx][ny] = (t[nx][ny] + 1) % 2;
							}
						}
					}
				}
			}
			bool flag = true;
			for(int k = 0;k < 10;k++){
				if(t[9][k]) flag = false;
			}
			if(flag){
				for(int k = 0;k < 10;k++){
					for(int l = 0;l < 10;l++) {
						cout << (!l ? "" : " ") << b[k][l];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

bool solve( int data[10][10], int answer[10][10], int t )
{
	if( t == 8 ){
		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				if( data[j][i] == 1 ) return false;
			}
		}
		return true;
	}

	for( int i = 1;i < 9;i++ ){
		if( data[i][t] == 1 ){
			data[i][t] = !data[i][t];
			data[i - 1][t + 1] = !data[i - 1][t + 1];
			data[i][t + 1] = !data[i][t + 1];
			data[i + 1][t + 1] = !data[i + 1][t + 1];
			data[i][t + 2] = !data[i][t + 2];

			answer[i][t + 1] = 1;

		}
	}

	return solve( data, answer, t + 1 );

}



int main(int argc, char const* argv[])
{
	int data[10][10];
	int answer[10][10];
	int n;

	cin >> n;

	for( int k = 0;k < n;k++ ){

		for( int i = 0;i < 10;i++ ){
			for( int j = 0;j < 10;j++ ){
				cin >> data[j][i];
				answer[j][i] = 0;
			}
		}

		solve( data, answer, 0 );

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

C++: #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool mem[12][12],cop[12][12],done[12][12];

int main(){
  int n;cin>>n;
  while(n--){
    lol(i,10)lol(j,10)cin>>mem[i][j];
    bool flag[10],tmp[10];
    for(int p=1;p<=1024;p++){
      lol(i,10)flag[i]=tmp[i];
      lol(i,10)lol(j,10)cop[i][j]=mem[i][j];
      for(int k=0;k<10;k++){
	lol(i,10){
	  if(!flag[i])continue;
	  for(int j=max(0,i-1);j<=min(9,i+1);j++)cop[k][j]^=1;
	  cop[k+1][i]^=1;
	}
	lol(i,10)done[k][i]=flag[i];
	lol(i,10)flag[i]=cop[k][i];
      }
      bool na=false;
      lol(i,10)na|=flag[i];
      if(!na){
	cout<<endl;
	lol(i,10){
	  lol(j,10){
	    if(j)cout<<" ";
	    cout<<done[i][j];
	  }
	  cout<<endl;
	}
      }
      for(int i=0;i<10;i++){
	int r=pow(2,i);
	if(p%r==0)tmp[i]^=1;
      }
    }
  }
  return 0;
}