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 <cstdio>
using namespace std;

int mask[12];
int conv[(1<<10)+10];
int save[12];

int main(){
	for(int line=0;line<1<<10;++line){
		int m = 0;

		if((line >> 0) & 1)m ^= 3;
		if((line >> 9) & 1)m ^= 3 << 8;

		for(int i=1;i<9;++i){
			if((line >> i) & 1){
				m ^= 7 << (i - 1);
			}
		}

		conv[line] = m;
	}

	int n;
	scanf("%d", &n);

	while(n--){
		for(int y=0;y<10;++y){
			int m = 0, f;
			for(int x=0;x<10;++x){
				scanf("%d", &f);
				m = (m << 1) + f;
			}
			mask[y] = m;
		}

		for(int line=0;line<1<<10;++line){
			int prev = mask[0] ^ conv[line];
			int curr = mask[1] ^ line;

			save[0] = line;

			for(int y=1;y<9;++y){
				int doit = prev;
				int nprev = curr ^ conv[doit];
				int ncurr = mask[y+1] ^ doit;

				prev = nprev;
				curr = ncurr;

				save[y] = doit;
			}

			save[9] = prev;

			if(curr ^ prev){
				continue;
			}

			for(int y=0;y<10;++y){
				int m = save[y];
				for(int x=9;x>=0;--x){
					if(x != 9)printf("%c", ' ');
					printf("%d", (m >> x) & 1);
				}
				puts("");
			}

			break;
		}
	}
	return 0;
}

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

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

int main(){
	int m;
	cin >> m;
	for(int i = 0;i < m;i++){
		int a[10][10];
		for(int j = 0;j < 10;j++){
			for(int k = 0;k < 10;k++) cin >> a[j][k];
		}
		for(int j = 0;j < 1024;j++){
			int b[10][10] = {},t[10][10];
			for(int k = 0;k < 10;k++){
				for(int l = 0;l < 10;l++){
					t[k][l] = a[k][l];
				}
			}
			for(int k = 0;k < 10;k++){
				if((j >> k) & 1){
					b[0][k] = 1;
					for(int l = 0;l < 4;l++){
						int nx = dx[l],ny = k + dy[l];
						if(ny >= 0 && ny < 10){
							t[nx][ny] = (t[nx][ny] + 1) % 2;
						}
					}
				}
			}
			for(int k = 0;k < 9;k++){
				for(int l = 0;l < 10;l++){
					if(t[k][l]){
						b[k + 1][l] = 1;
						for(int n = 0;n < 5;n++){
							int nx = k + 1 + dx[n],ny = l + dy[n];
							if(nx >= 0 && nx < 10 && ny >= 0 && ny < 10){
								t[nx][ny] = (t[nx][ny] + 1) % 2;
							}
						}
					}
				}
			}
			bool flag = true;
			for(int k = 0;k < 10;k++){
				if(t[9][k]) flag = false;
			}
			if(flag){
				for(int k = 0;k < 10;k++){
					for(int l = 0;l < 10;l++) {
						cout << (!l ? "" : " ") << b[k][l];
					}
					cout << endl;
				}
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int souchi[11][11];
int xx[]={1,-1,0,0,0};
int yy[]={0,0,1,-1,0};

void f(int a,int b){
	int i;
	for(i=0;i<5;i++){
		if(a+xx[i]<0||10<=a+xx[i]||b+yy[i]<0||10<=b+yy[i])continue;
		souchi[a+xx[i]][b+yy[i]]^=1;
	}
}

int main() {
	int n=in();
	int i;
	for(i=0;i<n;i++){
		int a,b;
		int tmp[11][11];
		int res[11][11];
		for(a=0;a<10;a++){
			for(b=0;b<10;b++){
				cin>>tmp[a][b];
			}
		}
		int bit;
		for(bit=0;bit<1<<10;bit++){
			for(a=0;a<10;a++){
				for(b=0;b<10;b++){
					souchi[a][b]=tmp[a][b];
					res[a][b]=0;
				}
			}
			for(b=0;b<10;b++){
				if(bit>>b&1){
					f(0,b);
					res[0][b]=1;
				}
			}
			for(a=0;a<9;a++){
				for(b=0;b<10;b++){
					if(souchi[a][b]){
						f(a+1,b);
						res[a+1][b]=1;
					}
				}
			}
			bool ok=true;
			for(b=0;b<10;b++){
				if(souchi[9][b])ok=false;
			}
			if(ok){
				for(a=0;a<10;a++){
					for(b=0;b<10;b++){
						cout<<res[a][b]<<" ";
					}
					cout<<endl;
				}
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int f[10][10];
int temp[10][10];
int dx[5] = {1,0,0,-1,0};
int dy[5] = {0,1,0,0,-1};
vector<pair<int,int> > ans;

void change(int y,int x)
{
	if(temp[y-1][x] == 1)
	{
		ans.push_back(make_pair(y,x));
		rep(i,5)
		{
			int ny = y + dy[i];
			int nx = x + dx[i];

			if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			{
				if(temp[ny][nx] == 1) temp[ny][nx] = 0;
				else temp[ny][nx] = 1;
			}
		}
	}
}
void dfs(int y,int x)
{
	rep(i,10) rep(j,10) temp[i][j] = f[i][j];
	ans.clear();
	REP(i,1,9)
	{
		rep(j,10)
		{
			if(i == y)
			{
				if(j >= x)
				{
					change(i,j);
				}
			}
			else if(i > y)
			{
				change(i,j);	
			}
		}
	}
	int cnt = 0;
	rep(i,10) rep(j,10) if(temp[i][j] == 1) cnt++;

	if(cnt == 0) return;
	else
	{
		if(x < 9)
		{
			dfs(y,x+1);
		}
		else if(x == 9)
		{
			dfs(y+1,0);
		}
	}
}

int main()
{
	int n;
	cin >> n;

	rep(i,n)
	{
		memset(f,0,sizeof(f));
		memset(temp,0,sizeof(temp));

		rep(j,10)
		{
			rep(k,10)
			{
				cin >> f[j][k];
			}
		}
		
		dfs(1,0);

		bool p[10][10];
		rep(j,10) rep(k,10) p[j][k] = false;

		rep(j,ans.size())
		{
			p[ans[j].first][ans[j].second] = true;
		}
		

		rep(j,10)
		{
			rep(k,10)
			{
				if(p[j][k]) cout << 1;
				else cout << 0;

				if(k == 9) cout << endl;
				else cout << " ";
			}
		}
	}
	return 0;
}

C++: //38
#include<iostream>
#include<algorithm>

using namespace std;

#define M ((1<<10)-1)

int main(){
  int n;
  cin>>n;
  while(n--){
    unsigned u[10]={};
    for(int y=0;y<10;y++){
      for(int x=0;x<10;x++){
	int b;
	cin>>b;
	u[y]=(u[y]<<1)+b;
      }
    }
    unsigned a[10];
    for(a[0]=0;;a[0]++){
      unsigned c[10];
      copy(u,u+10,c);
      c[0]^=a[0]^(a[0]<<1&M)^a[0]>>1;
      c[1]^=a[0];
      for(int i=1;i<9;i++){
	a[i]=c[i-1];
	c[i]^=a[i]^(a[i]<<1&M)^a[i]>>1;
	c[i+1]^=a[i];
      }
      a[9]=c[8];
      if((a[9]^(a[9]<<1&M)^a[9]>>1^c[9])==0){
	break;
      }
    }
    for(int y=0;y<10;y++){
      for(int x=9;x>=0;x--){
	cout<<!!(1<<x&a[y])<<((x==0)?'\n':' ');
      }
    }
  }
  return 0;
}