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 <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int L[10][10]; 
int F[10][10]; 
int R[10][10];

void init() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            F[i][j] = 0;
        }
    }
}

void input() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cin >> L[i][j];
        }
    }
}

bool check( int r, int c ) {
    int b = L[r][c];
    b ^= F[r][c];
    if ( r - 1 >= 0 ) b ^= F[r-1][c];
    if ( r + 1 < 10 ) b ^= F[r+1][c];
    if ( c - 1 >= 0 ) b ^= F[r][c-1];
    if ( c + 1 < 10 ) b ^= F[r][c+1];
    return b == 1;
}

void output() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cout << F[i][j];
            if ( j + 1 < 10 ) cout << " ";
        }
        cout << endl;
    }
}

void flip( int r, int c ) {
    int b = L[r][c];
    b ^= F[r][c];
    if ( r - 1 >= 0 ) b ^= F[r-1][c];
    if ( r + 1 < 10 ) b ^= F[r+1][c];
    if ( c - 1 >= 0 ) b ^= F[r][c-1];
    if ( c + 1 < 10 ) b ^= F[r][c+1];
    R[r][c] = b;
}

bool solve( int r ) {
    if ( r >= 10 ) {
        return true;
    }
    if ( r == 0 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            for ( int j = 0; j < 10; ++ j ) {
                F[r][j] = i & ( 1 << j ) ? 1 : 0;
            }
            if ( solve( r + 1 ) ) return true;
        }
    } else if ( r < 10 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            for ( int j = 0; j < 10; ++ j ) {
                F[r][j] = i & ( 1 << j ) ? 1 : 0;
            }
            bool flag = true;
            for ( int j = 0; j < 10; ++ j ) {
                if ( check( r - 1, j ) ) flag = false;
            }
            if ( flag && solve( r + 1 ) ) return true;
        }
    }

    return false;
}

int main() {
    int n;
    while ( cin >> n ) {
        for ( int i = 0; i < n; ++ i ) {
            init();
            input();
            solve( 0 );
            output();
        }
    }
    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];

    memset(ans,0,sizeof(ans));

    rep(k,1024){
      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==0)break;
    }
    rep(i,10){
      rep(j,10){
        if(j)cout<<" ";
        cout<<ans[i][j];
      }
      cout<<endl;
    }
  }
}

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){
	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;
}

C++: #include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

int a[10][10],b[10][10],ans[10][10],dx[]={1,0,-1,0,0},dy[]={0,1,0,-1,0};

void init(void){
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      b[i][j]=a[i][j];
      ans[i][j]=0;
    }
  }
}

void rev(int x, int y){
  for(int k=0;k<5;k++){

    int ny=y+dy[k],nx=x+dx[k];

    if( 0<=ny && 0<=nx && ny<10 && nx<10)
      b[ny][nx]=!b[ny][nx];
  }
}

int ok(void){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      if(b[i][j])return 0;
  return 1;
}

void solve(int p[]){
  init();

  for(int i=0;i<10;i++){
    if(p[i])rev(i,0);
    ans[0][i]=p[i];
  }
  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      if(b[i-1][j]){
	rev(j,i);
	ans[i][j]=1;
      }
    }
  }

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

void func(int p[], int cnt){
  if(9<cnt)solve(p);
  else {
    p[cnt]=0;
    func(p,cnt+1);
    p[cnt]=1;
    func(p,cnt+1);
  }
}

int main(void){
  int n;

  cin >> n;

  while(n--){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	cin >> a[i][j];

    int p[10]={0};
    func(p,0);
  }

  return 0;
}