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 <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

bool field[11][11], ans[11][11];

int main(){
  int n;
  cin >> n;
  while(n--){
    for(int i = 0 ; i < 10 ; i++){
      for(int j = 0 ; j < 10 ; j++){
	cin >> field[i][j];
      }
    }
    
    memset(ans, 0, sizeof(ans));
    
    for(int y = 0 ; y < 10 ; y++){
      for(int x = 0 ; x < 10 ; x++){
	if(y == 0 && x == 0){
	  if(field[0][0] && field[0][1] && field[1][0] && field[1][1]) ans[0][0] = 1;
	}
	else if(y == 0 && x == 9){
	  if(field[0][9] && field[0][8] && field[1][8] && field[1][9]) ans[0][9] = 1;
	}
	else if(y == 9 && x == 0){
	  if(field[9][0] && field[8][0] && field[8][1] && field[9][1]) ans[9][0] = 1;
	}
	else if(y == 9 && x == 9){
	  if(field[9][9] && field[9][8] && field[8][9] && field[8][8]) ans[9][9] = 1;
	}
	else if(y == 0){
	  if(field[0][x] && field[0][x+1] && field[1][x] && field[0][x-1]) ans[0][x] = 1;
	}
	else if(x == 0){
	  if(field[y][0] && field[y+1][0] && field[y][1] && field[y-1][0]) ans[y][0] = 1;
	}
	else if(y == 9){
	  if(field[9][x] && field[9][x+1] && field[8][x] && field[9][x-1]) ans[9][x] = 1;
	}
	else if(x == 9){
	  if(field[y][9] && field[y+1][9] && field[y][8] && field[y-1][9]) ans[y][0] = 1;
	}
	else if(field[y][x] && field[y-1][x] && field[y+1][x] && field[y][x-1] && field[y][x+1]){
	  ans[y][x] = 1;
	}
	else if(!field[y][x] && !field[y][x+1] && field[y-1][x] && field[y][x-1] &&
		field[y+1][x] && field[y+1][x+1] && field[y-1][x+1] &&
		field[y][x+2]){
	  ans[y][x] = 1, ans[y][x+1] = 1;
	}
      }
    }

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

C++: #include <iostream>
#include <algorithm>
#define SIZE 10
using namespace std;

class State{
public:
  int data[SIZE][SIZE];
  int put[SIZE][SIZE];
  State() {
    fill((int*)put, (int*)put+SIZE*SIZE, 0);
  }
  void puts(int x, int y) {
    static int d[5][2] = {{0,-1},{1,0},{0,1},{-1,0},{0,0}};
    put[y][x] = 1;
    for(int k = 0; k < 5; k++) {
      int nx = x + d[k][0];
      int ny = y + d[k][1];
      if(nx < 0 || nx >= SIZE) continue;
      if(ny < 0 || ny >= SIZE) continue;
      data[ny][nx] = -(data[ny][nx] - 1);
    }
  }
  bool isAll0() {
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	if(data[i][j] != 0) return false;
      }
    }
    return true;
  }
  void show() {
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	cout << put[i][j];
      }
      cout << endl;
    }
  }
};

bool rec(State s, int x, int y) {
  static int d[5][2] = {{0,-1},{1,0},{0,1},{-1,0},{0,0}};
  if(s.isAll0()) {
    s.show();
    return true;
  }

  for(int i = y; i < SIZE; i++) {
    for(int j = x; j < SIZE; j++) {
      bool flag = false;
      for(int k = 0; k < 5; k++) {
	int nx = j + d[k][0];
	int ny = i + d[k][1];
	if(nx < 0 || nx >= SIZE) continue;
	if(ny < 0 || ny >= SIZE) continue;
	if(s.data[ny][nx] == 1) {
	  flag = true;
	  break;
	}
      }
      if(flag) {
	if(i > 0 && s.data[i-1][j] == 0) continue;
	State tmp = s;
	tmp.puts(j, i);
	int nx, ny;
	nx = j + 1;
	ny = i;
	if(nx >= SIZE) {
	  nx = 0;
	  ny++;
	}
	if(rec(tmp, nx, ny)) {
	  return true;
	}
	if(i > 0 && s.data[i-1][j] == 1) return false;
      }
    }
  }
  return false;
}

main() {
  int n;
  cin >> n;
  for(int t = 0; t < n; t++) {
    State s;
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	cin >> s.data[i][j];
      }
    }
    rec(s, 0, 0);
  }
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,0,-1,1,-1};
const int dx[] = {0,-1,0,1,0,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

const int W = 10,H = 10;
int tile[W][H];
int opt[W][H];
int flip[W][H];

int get(int x,int y){
  int c = tile[x][y];
  rep(i,5){
    int nx = x+dx[i],ny = y+dy[i];
    if(value(nx,ny,W,H)){
      c += flip[nx][ny];
    }
  }
  return c % 2;
}

int calc(){
  REP(i,1,W){
    rep(j,H){
      if(get(i-1,j) != 0){
        flip[i][j] = 1;
      }
    }
  }
  rep(j,H){
    if(get(W-1,j) != 0)
      return -1;
  }
  int res = 0;
  rep(i,W){
    rep(j,H){
      res += flip[i][j];
    }
  }
  return res;
}

void solve(){
  int res = -1;
  rep(i,1 << H){
    memset(flip, 0, sizeof(flip));
    rep(j,W){
      flip[0][H-j-1] = i >> j & 1;
    }
    if(calc() != -1){
      break;
    }
  }
  rep(i,W){
    rep(j,H){
      if(j) cout << ' ';
      cout << flip[i][j] ;
    }
    cout << endl;
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  rep(x,n){
    rep(i,W){
      rep(j,H){
        cin >> tile[i][j];
      }
    }
    solve();
  }
  return 0;
}