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>
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++){
		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<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<complex>

#define f first
#define s second
#define mp make_pair

#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()

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

const int mask = (1<<10)-1;

int main(){
  int n;
  scanf("%d",&n);
  while(n --> 0){
    int data[10] = { 0 };
    REP(i,10) REP(j,10){
      int tmp; scanf("%d",&tmp);
      if(tmp == 1) data[i] |= (1 << j);
    }

    REP(k,(1<<10)){
      int d[10]; REP(i,10) d[i] = data[i];
      d[0] ^= k; d[0] ^= (k<<1); d[0] ^= (k>>1);
      d[1] ^= k;

      int ans[10] = { k };
      for(int i=0; i<9; i++){
        int tmp = 0;
        REP(j,10){
          if(d[i] & (1<<j)){
            tmp |= (1<<j);
          }
        }
        d[i] ^= tmp;
        d[i+1] ^= tmp; d[i+1] ^= (tmp<<1); d[i+1] ^= (tmp>>1);
        if(i!=8) d[i+2] ^= tmp;
        ans[i+1] = tmp;
      }
      if((d[9] & mask) == 0){
        REP(i,10) REP(j,10)
          printf("%d%c",((ans[i]&(1<<j))==0?0:1),(j==9?'\n':' '));
        break;
      }
    }
  }

  return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
         vector<int> x(10);
         for(int i=0; i<10; ++i){
             int a = 1;
             for(int j=0; j<10; ++j){
                 int b;
                 cin >> b;
                 if(b)
                     x[i] |= a;
                 a <<= 1;
             }
         }

         vector<vector<int> > dp(11, vector<int>(1<<10, 0));
         for(int i=0; i<10; ++i){
             for(int j=0; j<(1<<10); ++j){
                 int tmp = x[i];
                 tmp ^= dp[i][j];
                 tmp ^= j;
                 tmp ^= (j<<1) & ((1<<10)-1);
                 tmp ^= (j>>1);
                 dp[i+1][tmp] = j;
             }
         }

         vector<int> ret(10);
         int j = 0;
         for(int i=9; i>=0; --i)
             j = ret[i] = dp[i+1][j];

         for(int i=0; i<10; ++i){
             bitset<10> bs(ret[i]);
             cout << bs[0];
             for(int j=1; j<10; ++j)
                 cout << ' ' << bs[j];
             cout << endl;
         }
    }
}

C++: #include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int H = 10;
const int W = 10;

void disp(vector< vector<int> > &v){
  cout <<"----------" <<endl;
  REP(i, H){
    REP(j, W) cout <<v[i][j];
    cout <<endl;
  }
}

void shoot(int y, int x, vector< vector<int> > &v){
  v[y][x] = !v[y][x];
  if(y + 1 < H) v[y + 1][x] = !v[y + 1][x];
  if(y - 1 > -1) v[y - 1][x] = !v[y - 1][x];
  if(x + 1 < W) v[y][x + 1] = !v[y][x + 1];
  if(x - 1 > -1) v[y][x - 1] = !v[y][x - 1];
}

vector<P> change(vector< vector<int> > &v){
  vector<P> res;
  FOR(y, 1, v.size()){
    REP(x, v[y].size()){
      if(v[y - 1][x] == 1){
        shoot(y, x, v);
        res.push_back(P(y, x));
      }
    }
  }
  return res;
}

bool check(vector< vector<int> > &v){
  REP(i, v.size()) REP(j, v[i].size()) if(v[i][j] == 1) return false;
  return true;
}

vector<P> solve(){
  vector< vector<int> > v(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >>v[i][j];
  vector<P> res;
  REP(b, (1 << W)){
    vector< vector<int> > vv = v;
    vector<P> tmp;
    REP(i, W){
      if(!(1 & (b >> i))) continue;
      shoot(0, i, vv);
      tmp.push_back(P(0, i));
    }
    vector<P> ans = change(vv);
    REP(i, tmp.size()) ans.push_back(tmp[i]);
    if(check(vv)){ res = ans; break; }
  }
  return res;
}

int main() {
  int N; cin >>N;
  while(N--){
    vector<P> r = solve();
    vector< vector<int> > ans(H, vector<int>(W, 0));
    REP(i, r.size()) ans[r[i].first][r[i].second] = 1;
    REP(i, H){
      REP(j, W) cout <<(j != 0 ? " ": "") <<ans[i][j];
      cout <<endl;
    }
  }
  return 0;
}