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 <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

bool ans[10][10];
bool ba[10][10];
int dx[] = {-1,0,0,0,1};
int dy[] = {0, -1,0, 1, 0};

bool judge(int x, int y) {
  int res = ba[x][y];
  REP(k,5) {
    int xx = x + dx[k];
    int yy = y + dy[k];
    if (xx < 0 || xx >= 10 || yy < 0 || yy >= 10) continue;
    if (ans[xx][yy]) res++;
  }
  return res % 2;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    REP(y,10)
      REP(x,10)
      cin >> ba[x][y];
    
    for (int i=0; i<(1<<10); ++i) {
      memset(ans, 0, sizeof(ans));
      REP(j,10)
        if ((i>>j)&1)
          ans[j][0] = 1;
      for(int y=1; y<10; ++y) {
        REP(x,10) {
          if (judge(x,y-1))
            ans[x][y] = 1;
        }
      }
      bool f = 1;
      REP(i,10)
        if (judge(i, 9)) f = 0;
      if (f) 
        break;
    }
    REP(y,10) {
      REP(x,10)
        cout << ans[x][y] << " ";
      cout << endl;
    }
  }
}

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

bool grid[10][10];

void rev(int y,int x){
  int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>10 || sx>10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  bool ans[10][10];

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

    for(int i=0;i<(1<<10);i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++)grid[j][k] = tmp[j][k];
      }

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = true;
	}else ans[0][j] = false;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = true;
	  }else ans[j][k] = false;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<9;j++)cout << ans[i][j] << " ";
      cout << ans[i][9] << endl;
    }
    if(t)cout << endl;
  }
}

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 n;
int state[10][10];
int ans[10][10];

void pass(int y, int x) {
    for (int i=0; i<5; ++i) {
        if (0 <= y + dy[i] && y + dy[i] < 10 && 0 <= x + dx[i] && x + dx[i] < 10) {
            state[y + dy[i]][x + dx[i]] = 1 - state[y + dy[i]][x + dx[i]];
        }
    }
    ans[y][x] = 1 - ans[y][x];
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        memset(state, 0, sizeof(state));
        memset(ans, 0, sizeof(ans));
        for (int j=0; j<10; ++j) {
            if ((bt>>j) & 1) {
                pass(0, j);
            }
        }
        for (int i=1; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i-1][j] == 1) {
                    pass(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() {
    cin >> n;
    while (n --) {
        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 <string>
#include <algorithm>
#include <vector>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int f[10][10];
int temp[10][10];
int dx[5] = {1,0,0,-1,0};
int dy[5] = {0,1,0,0,-1};
vector<pair<int,int> > ans;

void change(int y,int x)
{
	if(temp[y-1][x] == 1)
	{
		ans.push_back(make_pair(y,x));
		rep(i,5)
		{
			int ny = y + dy[i];
			int nx = x + dx[i];

			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			{
				if(temp[ny][nx] == 1) temp[ny][nx] = 0;
				else temp[ny][nx] = 1;
			}
		}
	}
}
void dfs(int y,int x)
{
	rep(i,10) rep(j,10) temp[i][j] = f[i][j];
	ans.clear();
	REP(i,1,10)
	{
		rep(j,10)
		{
			if(i == y)
			{
				if(j >= x)
				{
					change(i,j);
				}
			}
			else if(i > y)
			{
				change(i,j);	
			}
		}
	}
	int cnt = 0;
	rep(i,10) rep(j,10) if(temp[i][j] == 1) cnt++;

	if(cnt == 0) return;
	else
	{
		if(y == 9 && x == 9)
		{
			return;
		}
		else if(x < 9)
		{
			dfs(y,x+1);
		}
		else if(x == 9)
		{
			dfs(y+1,0);
		}
	}
}

int main()
{
	int n;
	cin >> n;

	rep(i,n)
	{
		memset(f,0,sizeof(f));
		memset(temp,0,sizeof(temp));

		rep(j,10)
		{
			rep(k,10)
			{
				cin >> f[j][k];
			}
		}

		dfs(1,0);

		bool p[10][10];
		rep(j,10) rep(k,10) p[j][k] = false;

		rep(j,ans.size())
		{
			p[ans[j].first][ans[j].second] = true;
		}
		
		rep(j,10)
		{
			rep(k,10)
			{
				if(p[j][k]) cout << 1;
				else cout << 0;

				if(k == 9) cout << endl;
				else cout << " ";
			}
		}
	}
	return 0;
}