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<vector>
#include<queue>
#include<algorithm>
#include<cstring>

#define MAX 12

using namespace std;

class CMap{
public:
	int m[MAX][MAX];
	vector< pair<int, int> > vHist;

	CMap()
	{
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void PassParticle(int i, int j)
	{
		const int di[] = {0,-1,0,1,0};
		const int dj[] = {0,0,1,0,-1};

		for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
			m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;

		vHist.push_back( make_pair( i, j ) );
	}

	bool NoLight() const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}

	void Print() const
	{
		for(int i = 1; i < MAX - 1; ++i){
			cout << m[i][1];
			for(int j = 2; j < MAX - 1; ++j)
				cout << ' ' << m[i][j];
			cout << '\n';
		}
	}

	void PrintAns() const
	{
		int a[MAX][MAX] = {{0,},};
		for( unsigned int i = 0; i < vHist.size(); ++i)
			a[vHist[i].first][vHist[i].second] = 1;

		for(int i = 1; i < MAX - 1; ++i){
			cout << a[i][1];
			for(int j = 2; j < MAX - 1; ++j)
				cout << ' ' << a[i][j];
			cout << '\n';
		}
	}
	
	bool operator==(const CMap &t) const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( t.m[i][j] != m[i][j] )
					return false;
		return true;
	}
};
inline bool inRange(int t, int min, int max){
	return (min <= t && t < max);
}
void BFS(CMap &stm, CMap &ret){
	vector< CMap > q;

	q.push_back( stm );

	while( !q.empty() ){
		CMap M = q[0];
		q.erase( q.begin() );

		if( M.NoLight() )
		{
			ret = M;
			break;
		}

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				CMap add;
				int cnt1 = 0;
				const int di[] = {0,-1,0,1,0};
				const int dj[] = {0,0,1,0,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
					if( M.m[i+di[k]][j+dj[k]] == 1 &&
						inRange( i+di[k], 1, MAX - 1) &&
						inRange( j+dj[k], 1, MAX - 1 ) )
						++cnt1;

				if( cnt1 >= 3 )
				{
					add = M;
					add.PassParticle( i, j );
					if( q.end() == find( q.begin(), q.end(), add ) )
						q.push_back( add );
				}
			}
		}
	}
}
void SearchShootingPoints(CMap &stm){
	for(int i = 1; i < MAX - 1; ++i){
		for(int j = 1; j < MAX - 1 ; ++j){
			int cnt1 = 0;
			const int di[] = {0,-1,0,1,0};
			const int dj[] = {0,0,1,0,-1};

			for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
				if( stm.m[i+di[k]][j+dj[k]] == 1 &&
					inRange( i+di[k], 1, MAX - 1) &&
					inRange( j+dj[k], 1, MAX - 1 ) )
					++cnt1;

			if( cnt1 >= 3 )
			{
				stm.PassParticle( i, j );
			}
		}
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D )
	{
		CMap M;
		CMap Answer;

		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1 ; ++j)
				cin >> M.m[i][j];

		SearchShootingPoints( M );

		M.PrintAns();
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

void solve() {
  int a[10][10];
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> a[i][j];
    }
  }
  int tmp[10][10];
  for (int i = 0; i < 1 << 10; i++) {
    memset(tmp, 0, sizeof(tmp));
    for (int j = 0; j < 10; j++) {
      if (i >> j & 1) tmp[0][j] = 1;
    }
    for (int j = 0; j + 1 < 10; j++) {
      for (int k = 0; k < 10; k++) {
        int sum = tmp[j][k];
        for (int l = 0; l < 4; l++) {
          int ny = j + dy[l], nx = k + dx[l];
          if (ny >= 0 && ny < 10 && nx >= 0 && nx < 10) sum += tmp[ny][nx];
        }
        if ((sum + a[j][k]) % 2 == 0) continue;
        tmp[j + 1][k] = 1;
      }
    }
    int tmp2[10][10];
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        tmp2[j][k] = tmp[j][k];
        for (int l = 0; l < 4; l++) {
          int ny = j + dy[l], nx = k + dx[l];
          if (ny >= 0 && ny < 10 && nx >= 0 && nx < 10) (tmp2[j][k] += tmp[ny][nx]) %= 2;
        }
      }
    }
    bool ng = false;
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        ng |= tmp2[j][k] != a[j][k];
      }
    }
    if (ng) continue;
    for (int j = 0; j < 10; j++) {
      for (int k = 0; k < 10; k++) {
        cout << tmp[j][k] << " \n"[k + 1 == 10];
      }
    }
    return;
  }
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve();
  }

  return 0;
}

C++: 
#include<iostream>
using namespace std;
enum{W=10,H=10};

bool clear(bool field[H][W]){
  bool ok=true;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)if(field[i][j])ok=false;
  return ok;
}

int main(){
  int n;
  bool field[H][W];
  bool dup[H][W];
  int bit[H];
  cin>>n;
  while(n-->0){

    for(bit[0]=0; bit[0] < (1<<10); bit[0]++){
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>field[i][j];
      for(int i=1;i<H;i++)bit[i]=0;
      for(int i=0;i<H;i++)for(int j=0;j<W;j++)dup[i][j]=field[i][j];
      for(int j=0;j<W;j++){
        if(!((bit[0]>>j)&1))continue;
        dup[0][j]^=1;
        dup[1][j]^=1;
        if(j>0)dup[0][j-1]^=1;
        if(j<W-1)dup[0][j+1]^=1;
      }

      for(int i=1;i<H;i++){
        for(int j=0;j<W;j++){
          if(dup[i-1][j]){
            bit[i]^=(1<<j);
            dup[i][j]^=1;
            dup[i-1][j]^=1;
            if(i<H-1)dup[i+1][j]^=1;
            if(j>0)dup[i][j-1]^=1;
            if(j<W-1)dup[i][j+1]^=1;
          }
        }
      }
      if(clear(dup))break;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(j!=0)cout<<" ";
        if(bit[i]&(1<<j))cout<<"1";
        else cout<<"0";
      }
      cout<<endl;
    }
  }
}