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<queue>
#include<algorithm>

using namespace std;

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

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

void rev(int x, int y){
  for(int k=0;k<5;k++)
    if( 0<=y+dy[k] && 0<=x+dx[k] && y+dy[k]<10 && x+dx[k]<10)
      b[y+dy[k]][x+dx[k]]=b[y+dy[k]][x+dx[k]]?0:1;
}

int ok(void){
  for(int i=0;i<10;i++)
    for(int j=0;j<10;j++)
      if(b[i][j])return 0;
  return 1;
}

void solve(int p[]){
  init();

  for(int i=0;i<10;i++)
    if(p[i])rev(i,0);

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

  if(ok()){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cout << ans[i][j];
	if(j<9)cout << " ";
	else cout << endl;
      }
    }
  }
}

void func(int p[], int cnt){
  if(9<cnt)solve(p);
  else {
    func(p,cnt+1);
    p[cnt]=1;
    func(p,cnt+1);
  }
}

int main(void){
  int n;

  cin >> n;

  while(n--){

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++)
	cin >> a[i][j];

    int p[10]={0};
    func(p,0);
  }

  return 0;
}

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

typedef long long ll;
#define rep(i,n) for(i=0;i<n;++i)
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define mp make_pair
#define pb push_back
#define fi first
#define sc second

bool inside(int x,int y)
{
	return(0<=x&&x<10 && 0<=y&&y<10);
}

int main()
{
	int i,j,k;
	int dx[5]={1,-1,0,0,0};
	int dy[5]={0,0,0,-1,1};

	int C;
	cin >>C;
	for(int cases=0;cases<C;++cases)
	{
		int f[10][10]={0};
		rep(i,10)rep(j,10) scanf(" %d",&f[i][j]);

		int ans[10][10]={0};

		//1???????????????????????????????±????
		int mask;
		for(mask=0; mask<(1<<10); ++mask)
		{
			//???????????§?°??????????????¨????
			int ta[10][10]={0};
			//?????£???????????¶???
			int t[10][10]={0};
			rep(i,10)rep(j,10) t[i][j]=f[i][j];
			//1??????????????¢
			rep(i,10)
			{
				if(mask>>i&1)
				{//?????¢?????????
					ta[0][i]=1;
					rep(j,5)
					{
						int nx=i+dx[j];
						int ny=0+dy[j];
						if(inside(nx,ny)) t[ny][nx]=!t[ny][nx];
					}
				}
			}

			for(i=0;i<10-1;++i)
			{//i???????????¨???
				rep(j,10)
				{
					if(t[i][j]==1)
					{
						ta[i+1][j]=1;
						rep(k,5)
						{
							int nx=j+dx[k];
							int ny=i+1+dy[k];
							if(inside(nx,ny)) t[ny][nx]=!t[ny][nx];
						}
					}
				}
			}

			bool valid=true;
			rep(i,10)rep(j,10) valid&=(t[i][j]==0);

			if(valid)
			{
				rep(i,10)rep(j,10) ans[i][j]=ta[i][j];
				break;
			}
		}

		//output
		rep(i,10)
		{
			rep(j,10)
			{
				if(j) printf(" ");
				printf("%d",ans[i][j]);
			}
			printf("\n");
		}
	}
}

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 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)
{
	//cout << "y:" << y << " x:" << x << endl;
	if(f[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)
			{
				f[ny][nx] = 0;
			}
		}
	}
}

void dfs(int y,int x)
{
	//cout << "y:" << y << " x:" << x << endl;
	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(f[i][j] == 1) cnt++;
		}
	}

	if(cnt == 0) return;
	else
	{
		if(y == 9)
		{
			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));

		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++: #include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define fr first
#define sc second
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int,pii> pip; 
const int INF = (1<<25);
const int dx[]={0,0,0,1,-1},dy[]={-1,1,0,0,0};

int d[10][10], b[10][10], a[10][10];

void flip(int x, int y) {
  a[y][x]=1;
  for(int i=0; i<5; i++) {
    b[y+dy[i]][x+dx[i]] = 1-b[y+dy[i]][x+dx[i]];
  }
}

int main() {

  int n;
  cin>> n;
  while(n--) {
    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cin>> d[i][j];
      }
    }

    for(int i=0; i<1024; i++) {
      memset(a, 0, sizeof(a));
      memcpy(b, d, sizeof(b));
      for(int j=0; j<10; j++) {
	if((i>>j-1) & 1) flip(j, 0);
      }

      for(int j=1; j<10; j++) {
	for(int k=0; k<10; k++) {
	  if(b[j-1][k]) flip(k, j);
	}
      }

      int cnt=0;
      for(int j=0; j<10; j++) {
	if(b[9][j]){
	  cnt++; break;
	}
      }

      if(!cnt) break;
    }

    for(int i=0; i<10; i++) {
      for(int j=0; j<10; j++) {
	cout << a[i][j]<< (j==9 ? "" : " ");
      }
      cout<< endl;
    }
  }
}