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>
#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++) {
    int j;
    if(i == y) j = x;
    else       j = 0;
    for(; 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;
	}
	}*/
      flag = true;
      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++) {
    if(t != 0) cout << endl;
    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 <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>


typedef long long ll;
const double Eps = 1e-5;

using namespace std;

int state[10][10];
int fired[10][10];

void fire(int x, int y)
{
	int dx[] = { 0, 0, 1, 0, -1 };
	int dy[] = { 0, -1, 0, 1, 0 };
	for (int i = 0; i < 5; ++i)
	{
		int tx = x + dx[i];
		int ty = y + dy[i];
		if (0 <= tx && tx < 10
			&& 0 <= ty && ty < 10)
		{
			state[ty][tx] = state[ty][tx] ? 0 : 1;
		}
	}
	fired[y][x] = 1;
}
bool is_alloff()
{
	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			if (state[i][j])
				return false;
	return true;
}
void print_state(int s[10][10])
{
	for (int i = 0; i < 10; ++i)
	{
		for (int j = 0; j < 9; ++j)
			printf("%d ", s[i][j]);
		printf("%d\n", s[i][9]);
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	while (n--)
	{
		int defState[10][10];
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
			{
				int t;
				scanf("%d", &t);
				defState[i][j] = t;
			}
		}

		for (int subset = 0; subset < 1 << 10; ++subset)
		{
			memcpy(state, defState, sizeof(state));
			memset(fired, 0, sizeof(fired));

			for (int i = 0; i < 10; ++i)
				if (subset & 1 << i)
					fire(i, 0);

			for (int i = 1; i < 10; ++i)
			{
				for (int j = 0; j < 10; ++j)
				{
					if (state[i-1][j])
						fire(j, i);
				}
			}

			if (is_alloff())
				break;
		}
		print_state(fired);
	}

	return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int dx[]={-1,0,0,1};
int dy[]={0,0,-1,0};
int main()
{
    int n;
	cin>>n;
	while(n--){
		int panel[10]={},ans[10]={};
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				int tmp;
				cin>>tmp;
				panel[i]|=tmp<<j;
			}
		}
		for(int i=0;i<(1<<10);i++){//1??????ans?????????
			ans[0]=i;
			for(int j=0;j<9;j++){//????????????ans????¨????
				for(int k=0;k<10;k++){//?????????????????°???
					int tmp=0;
					for(int l=0;l<4;l++){
						int nx=k+dx[l],ny=j+dy[l];
						if(0<=nx&&nx<10&&0<=ny&&ny<9)tmp+=(ans[ny]>>nx)&1;
					}
					if(tmp-(panel[j]>>k)&1)ans[j+1]|=1<<k;
				}
			}
			if(ans[9]==0){
				for(int i=0;i<10;i++){
					for(int j=0;j<10;j++){
						int tmp=(ans[i]>>j)&1;
						printf(j==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
	}
    return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int light[10][10];
bool solve(int n){
  int ans[10][10];
  int rslt[10];
  REP(i,10){
    if(i==0) REP(j,10)ans[i][j] = (n>>j&1);
    else REP(j,10) ans[i][j] = rslt[j];
    REP(j,10) rslt[j] = light[i][j];
    REP(j,10){
      if(j-1>=0)rslt[j] ^= ans[i][j-1];
      rslt[j] ^= ans[i][j];
      if(j+1<10)rslt[j] ^= ans[i][j+1];
      if(i-1>=0)rslt[j] ^= ans[i-1][j];
    }
  }
  bool right = true;
  REP(j,10) if(rslt[j]) right = false;
  if(right){
    REP(y,10){
      REP(x,10){
        if(x) cout<<" ";
        cout<<ans[y][x];
      }
      cout<<endl;
    }
  }
  return right;
}


int main(void){
  int N;
  cin>>N;
  while(N--){
    REP(y,10)REP(x,10) cin>>light[y][x];
    REP(i,1<<10) if(solve(i)) break;
  }
  return 0;
}