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 "bits/stdc++.h"

using namespace std;

typedef pair<int,int> pii;
typedef vector<int> vi;

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999
int ans[11][11]={};

vector<vector<int> > d(int y,int x,vector<vector<int> > t){
    int dx[]={0,0,0,-1,1};
    int dy[]={-1,0,1,0,0};
    rep(k,5){
        int ddy=y+dy[k],ddx=x+dx[k];
        if(ddx>=0&&ddy>=0&&ddx<10&&ddy<10){
            t[ddy][ddx]=!t[ddy][ddx];
        }
    }
    return t;
}

int main(){
    int n;
    cin>>n;
    rep(loop,n){
        vector<vector<int> > data;
        rep(i,10){
            vector<int> a(10);
            rep(j,10)cin>>a[j];
            data.pb(a);
        }
//        rep(i,10){rep(j,10)cout<<data[i][j]<<" ";cout<<endl;}
        rep(i,1<<10){
            vector<vector<int> > t=data;
            rep(j,11)rep(k,11)ans[j][k]=0;
            rep(j,10){
                ans[0][j]=((i&(1<<j))!=0);
                if(ans[0][j])t=d(0,j,t);
            }
            for(int j=1;j<10;j++){
                for(int k=0;k<10;k++){
                    if(t[j-1][k]==1){
                        ans[j][k]=1;
                        t=d(j,k,t);
                    }
                }
            }
            bool f=true;
            rep(j,10){
                if(t[9][j]==1)f=false;
            }
            if(f){
                rep(j,10){
                    rep(k,10){
                        if(k)cout<<" ";
                        cout<<ans[j][k];
                    }
                    cout<<endl;
                }
                break;
            }
        }
    }
}

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

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={0,0,0,1,-1},dy[]={-1,1,0,0,0};

int d[10][10], b[10][10], a[10][10];

void flip(int x, int y) {
  a[y][x]=1;
  for(int i=0; i<5; i++) {
    b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
  }
}

int main() {

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

    for(int i=0; i<1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(d));
      for(int j=0; j<10; j++) {
	if((i>>j) & 1) flip(j, 0);
      }

      for(int j=1; j<10; j++) {
	for(int k=0; k<10; k++) {
	  if(b[j-1][k]) flip(k, j);
	}
      }

      int cnt=0;
      for(int j=0; j<10; j++) {
	if(b[9][j]) {
	  cnt=1; break;
	}
      }
      
      if(cnt==0) break;
    }

    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cout << a[i][j]<< (j==9 ? "" : " ");
      }
      cout<< endl;
    }
  }
}