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

int main()
{
  int n;
  cin >> n;
  while(n--){
    int dtct[10][10];
    int dx[] = {-1, 0, 1, 0};
    int dy[] = {0, 0, 0, 1};
    for(int i = 0; i < 10; i++){
      for(int j = 0; j < 10; j++){
	cin >> dtct[i][j];
      }
    }
    
    for(int i = 0; i < 1 << 10; i++){
      int axi[10][10] = {{0}};
      int tmp[10][10] = {{0}};
      for(int j = 0; j < 10; j++){
	axi[0][j] = (i >> j) & 1;
	if(axi[0][j] == 0) continue;
	for(int k = 0; k < 4; k++){
	  int nx = j + dx[k], ny = dy[k];
	  if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
	  tmp[ny][nx]++;
	}
      }
      for(int j = 1; j < 10; j++){
	for(int k = 0; k < 10; k++){
	  if((dtct[j-1][k]+tmp[j-1][k])%2 == 1){
	    axi[j][k] = 1;
	    for(int l = 0; l < 4; l++){
	      int nx = k + dx[l], ny = j + dy[l];
	      if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
	      tmp[ny][nx]++;
	    }
	  }
	}
      }
      bool flag = true;
      for(int j = 0; j < 10; j++){
	if((tmp[9][j]+dtct[9][j])%2 == 1) flag = false;
      }
      if(flag){
	for(int j = 0; j < 10; j++){
	  for(int k = 0; k < 10; k++) cout << axi[j][k] << (k == 9 ? "\n":" ");
	}
	break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
using namespace std;
int x[10][10];
int main() {
	int n; cin >> n;
	for (int h = 0; h < n; h++) {
		for (int i = 1; i <= 10; i++) {
			for (int j = 1; j <= 10; j++)cin >> x[i][j];
		}

		for (int i = 0; i < (1 << 10); i++) {
			int bit[11]; for (int j = 0; j < 10; j++)bit[j + 1] = (i / (1 << j)) % 2;
			int T[12][12], V[12][12];
			for (int j = 0; j < 12; j++) {
				for (int k = 0; k < 12; k++) { T[j][k] = 0; V[j][k] = 0; }
			}

			for (int j = 1; j <= 10; j++) {
				if (bit[j] == 1) {
					T[0][j]++; T[0][j] %= 2;
					T[1][j]++; T[1][j] %= 2;
					T[0][j - 1]++; T[0][j - 1] %= 2;
					T[0][j + 1]++; T[0][j + 1] %= 2;
					V[0][j] = 1;
				}
			}
			for (int j = 1; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					if (T[j - 1][k + 0] != x[j - 1][k + 0]) {
						T[j - 1][k + 0]++; T[j - 1][k + 0] %= 2;
						T[j + 0][k + 0]++; T[j + 0][k + 0] %= 2;
						T[j + 1][k + 0]++; T[j + 1][k + 0] %= 2;
						T[j + 0][k - 1]++; T[j + 0][k - 1] %= 2;
						T[j + 0][k + 1]++; T[j + 0][k + 1] %= 2;
						V[j][k] = 1;
					}
				}
			}
			bool OK = true; for (int k = 0; k < 10; k++) { if (T[9][k] != x[9][k])OK = false; }
			if (OK == true) {
				for (int j = 0; j < 10; j++) {
					for (int k = 0; k < 10; k++) {
						if (k)cout << ' '; cout << V[j][k];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;
typedef vector<vector<int> > matrix;

int dy[5] = { -1, 0, 0, 0, 1 };
int dx[5] = { 0, -1, 0, 1, 0 };

void print(matrix& mat) {
	REP(y, 10) {
		REP(x, 10) {
			cout << mat[y][x] << " ";
		}
		cout << endl;
	}
}

matrix mk_matrix(int n) {
	matrix mat(n);
	REP(i, n) {
		mat[i] = vector<int>(10, 0);
	}
	return mat;
}

void push(matrix& mat, int y, int x) {
	REP(i, 5) {
		int nx = x + dx[i];
		if (nx < 0 || nx >= 10) continue;
		int ny = y + dy[i];
		if (ny < 0 || ny >= 10) continue;
		mat[ny][nx] ^= 1;
	}
}

void solve(matrix& mat) {
	//?????????????????¨????????????????????????
	REP(i, 1024) {
		matrix mat_tmp = mat;
		matrix pushed = mk_matrix(10);
		int tmp = i;
		REP(j, 10) {
			if (!tmp) break;
			if (tmp & 1) {
				push(mat_tmp, 0, j);
				pushed[0][j] = 1;
				//print(mat_tmp);
			}
			tmp >>= 1;
		}

		FOR(y, 1, 10) {
			REP(x, 10) {
				if (mat_tmp[y - 1][x]) {
					push(mat_tmp, y, x);
					pushed[y][x] = 1;
					//print(mat_tmp);
				}
			}
		}
		//cout << i << endl;
		//print(mat_tmp);
		if (find(mat_tmp[9].begin(), mat_tmp[9].end(), 1) == mat_tmp[9].end()) {
			print(pushed);
			//cout << "solved." << endl;
			return;
		}
	}
}

bool AOJ0131()
{
	matrix mat = mk_matrix(10);
	REP(i, 10) {
		REP(j, 10) {
			cin >> mat[i][j];
		}
	}

	solve(mat);

	return true;
}

int main()
{
	int n;
	cin >> n;
	REP(i, n) AOJ0131();

	return 0;
}