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<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a/gcd(a,b)*b;
}
int n = 10;
bool in(int a, int b){
    if(a < 0 || a >= n || b < 0 || b >= n)return false;
    return true;
}
int dx[] = {0,0,1,0,-1};
int dy[] = {0,1,0,-1,0};

signed main(void) {
    int num;
    cin >> num;
    while(num--){
        vvi a(n,vi(n));
        rep(i,n)rep(j,n)cin >> a[i][j];
        rep(bit, 1<<n){
            vvi t = a;
            vvi ans(n,vi(n,0));
            rep(i,n)if(bit&(1<<i)){
                ans[0][i]++;
                rep(j,5){
                    int x = 0 + dx[j];
                    int y = i + dy[j];
                    if(in(x,y))t[x][y] ^= 1;
                }
            }
            rep(i,n-1)rep(j,n)if(t[i][j]){
                ans[i+1][j]++;
                rep(k,5){
                    int x = i+1 + dx[k];
                    int y = j + dy[k];
                    if(in(x,y))t[x][y] ^= 1;
                }
            }
            bool c = true;
            rep(j,n)if(t[n-1][j])c = false;
            if(c){
                rep(i,n)rep(j,n)cout << ans[i][j] << " \n"[j == n-1];
            }
        }
        vvi ans(n,vi(n,0));
    }
}

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

const int H = 10;
const int W = 10;
int G[H][W];
int ans[H][W];

void put(int i, int j) {
  static int di[] = {0,1,0,-1,0};
  static int dj[] = {1,0,-1,0,0};
  for(int k = 0; k < 5; ++k) {
    int ni = i + di[k];
    int nj = j + dj[k];
    if(ni < 0 || ni >= H) continue;
    if(nj < 0 || nj >= W) continue;
    G[ni][nj] ^= 1;
  }
}

bool rec(int i, int j) {
  if(j == W) {
    ++i;
    j = 0;
  }

  if(i == H) {
    for(int j = 0; j < W; ++j) {
      if(G[H-1][j]) return false;
    }
    return true;
  }

  if(i == 0) {
    ans[i][j] = 0;
    if(rec(i, j+1)) return true;
    ans[i][j] = 1;
    put(i, j);
    if(rec(i, j+1)) return true;
    put(i, j);
  } else {
    if(G[i-1][j]) {
      ans[i][j] = 1;
      put(i, j);
      if(rec(i, j+1)) return true;
      put(i, j);
    } else {
      ans[i][j] = 0;
      if(rec(i, j+1)) return true;
    }
  }
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cin >> G[i][j];
      }
    }
    rec(0, 0);
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        if(j) cout << " ";
        cout << ans[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

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

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

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];

    copy(b,mp);
    int ans[10][10]={};
    for(int i=0;!check(mp);i++){
      copy(mp,b),copy(b,mp);
      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];
      }
      cout <<endl;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

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

int judge(int *used){
  memcpy(b, a, sizeof(a));
  memset(res, 0, sizeof(res));

  rep(i, 10){
    if(!used[i]) continue;
    res[0][i] = 1;
    rep(d, 5){
      int ny = dy[d], nx = i + dx[d];

      if(ny < 0 || nx < 0 || ny >= 10 || nx >= 10) continue;
      b[ny][nx] = !b[ny][nx];
    }
  }
  
  REP(i, 1, 10){
    rep(j, 10){
      if(!b[i-1][j]) continue;
      res[i][j] = 1;
      rep(d, 5){
	int ny = i + dy[d], nx = j + dx[d];

	if(ny < 0 || nx < 0 || ny >= 10 || nx >= 10) continue;
	b[ny][nx] = !b[ny][nx];
      }
    }
  }
 
  rep(i, 10) rep(j, 10) if(b[i][j]) return 0;

 
  return 1;
}

bool solve(int i, int *used){
  if(i == 10){
    if(judge(used)) return 1;
    return 0;
  }

  if(solve(i+1, used)) return 1;
  used[i] = 1;
  if(solve(i+1, used)) return 1;
  used[i] = 0;

  return 0;
}

int main(){
  int n;
  scanf("%d", &n);
  while(n--){
    rep(i, 10) rep(j, 10) scanf("%d", &a[i][j]);

    int used[10];
    memset(used, 0, sizeof(used));
    solve(0, used);

    rep(i, 10){
      rep(j, 10) printf(j?" %d":"%d", res[i][j]); puts("");
    }
  }
  return 0;
}