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++: #define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>


#ifdef _DEBUG
#define typeof(X) std::identity<decltype(X)>::type //C++0x (for vs2010)
#else
#define typeof(X) __typeof__(X) // for gcc
#endif

#define sz(a)  int((a).size())
#define FOREACH(it, c) for (typeof((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define FOR(i,count) for (int i = 0; i < (int)(count); i++)

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
const int MODULO = 100000 ;
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef complex<double> Cd;

using namespace std;

bool flip[10][10];
bool tmp[10][10];

bool get(int h,int w){
	static int dh[] = {1,0,0,0,-1};
	static int dw[] = {0,1,0,-1,0};
	bool ret = flip[h][w];
	FOR(i,5){
		int nh = dh[i]+h,nw = dw[i]+w;
		if(0 <= nh && nh < 10 && 0 <= nw && nw < 10)
			ret ^= tmp[nh][nw];
	}

	return ret;
}

int main()
{
	int n; cin>>n;
	while(n--){
		FOR(i,10) FOR(j,10){ int x; cin>>x; flip[i][j] = x == 1; }
		FOR(i,2<<10){
			memset(tmp,0,sizeof(tmp));
			FOR(j,10) tmp[0][j] = (i & (1 << j)) != 0;
			for(int j = 1; j < 10; j++) for(int k = 0; k < 10; k++){
				tmp[j][k] = get(j-1,k);
			}
			bool ok = true;
			FOR(j,10) if(get(9,j)){
				ok = false;
				break;
			}
			if(ok) break;
		}
		FOR(i,10) FOR(j,10) printf("%d%c",tmp[i][j],j == 9 ? '\n' : ' ');
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
typedef vector<int> vi;
#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()
#define mp make_pair
#define pb push_back
#define f first
#define s second


bool ans[10][10];
int ban[10][10];

main(){
  int n;
  cin>>n;
  while(n--){
    rep(i,10)rep(j,10)cin>>ban[i][j];


    rep(k,1<<10){
      memset(ans,0,sizeof(ans));
      rep(i,10){
        rep(j,10){
          if(!i){
            ans[i][j]=!!(1<<i&k);
          }else{
            int t=ans[i-1][j]+ban[i-1][j];
            if(j<9)t+=ans[i-1][j+1];
            if(j)t+=ans[i-1][j-1];
            if(i>1)t+=ans[i-2][j];
            ans[i][j]=t%2;
          }
        }
      }
      int odd=0;
      rep(j,10)odd+=ans[9][j];
      if(!odd)break;
    }
    rep(i,10){
      rep(j,10){
        if(j)cout<<" ";
        cout<<ans[i][j];
      }
      cout<<endl;
    }
  }
}

C++: #include <iostream>
using namespace std;
int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
int field[12][12];
int afield[12][12];

void search(int y,int x) {
  int sum = 0;
  if(field[y][x] == 1) sum++;
  for(int i=0;i<4;i++) {
    if(field[y+dy[i]][x+dx[i]] == 1) {
      sum++;
    }
  }

  if(sum >= 3) {
    afield[y][x] = 1;
    if(field[y][x] == 1) field[y][x] = 0;
    else field[y][x] = 1;
    for(int i=0;i<4;i++) {
      if(field[y+dy[i]][x+dx[i]] == 1) {
	field[y+dy[i]][x+dx[i]] = 0;
      }
      else if(field[y+dy[i]][x+dx[i]] == 0) {
	field[y+dy[i]][x+dx[i]] = 1;
      }
    }
  }
  return;
}

int main() {
  int n;
  cin >> n;
  for(int i=0;i<n;i++) {

    for(int j=0;j<12;j++) { //init field
      for(int k=0;k<12;k++) {
	field[j][k] = 0;
	afield[j][k] = 0;
      }
    }

    for(int j=0;j<10;j++) { //input field
      for(int k=0;k<10;k++) {
	cin >> field[j+1][k+1];
      }
    }

    for(int j=0;j<10;j++) {
      for(int k=0;k<10;k++) {
	search(j+1,k+1);
      }
    }

    for(int j=0;j<10;j++) {
      for(int k=0;k<10;k++) {
	if(k != 0) cout << " ";
	cout << afield[j+1][k+1];
      }
      cout << endl;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;


void mark(int mp[10][10],int y,int x){
  int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||ny<0||nx>=10||ny>=10)continue;
    mp[ny][nx]=!mp[ny][nx];
  }
  mp[y][x]=!mp[y][x];
}

bool check(int mp[10][10]){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)if(mp[i][j])return 0;
  return 1;
}

int main(){
  int q;
  cin>>q;
  while(q--){
    int mp[10][10],b[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>mp[i][j],b[i][j]=mp[i][j];

    int ans[10][10]={};
    for(int i=0;!check(mp);i++){
      for(int j=0;j<10;j++)for(int k=0;k<10;k++) mp[j][k]=b[j][k];
      for(int j=0;j<10;j++)for(int k=0;k<10;k++) b[j][k]=mp[j][k];

      for(int j=0;j<10;j++)if((ans[0][j]=((i>>j)%2)))mark(mp,0,j);
      for(int j=1;j<10;j++)
	for(int k=0;k<10;k++)
	  if((ans[j][k]=mp[j-1][k]))mark(mp,j,k);
    }

    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	if(j) cout <<" ";
	cout << ans[i][j];
	assert(ans[i][j]==0||ans[i][j]==1);
      }
      cout <<endl;
    }
  }
  return 0;
}