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<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int a[12][12];
int f[12][12];
int res[12][12];
int b[20] = {1};
int dh[5] = {0, 0, 0, 1, -1};
int dw[5] = {0, 1, -1, 0, 0};

signed main(void){
  int i, j, k, l;
  rep1(i, 20)b[i] = b[i - 1] << 1;
  for(int testcase = 0;testcase >= 0;testcase++){
    int(n);
    for(;n--;){
      rep(i, 10)rep(j, 10)scanf("%d", &a[i + 1][j + 1]);
      rep(k, b[10]){
        rep(i, 12)rep(j, 12){
          f[i][j] = a[i][j];
          res[i][j] = 0;
        }
        for(int x = k, d = 1;x;x /= 2){
          res[1][d] = x % 2;
          if(x % 2 == 1)rep(l, 5)f[1 + dh[l]][d + dw[l]] ^= 1;
          ++d;
        }

        rep1(i, 10)rep(j, 10)if(f[i][j + 1] == 1){
          res[i + 1][j + 1] = 1;
          rep(l, 5)f[i + 1 + dh[l]][j + 1 + dw[l]] ^= 1;
        }
        bool isok = true;
        rep(i, 10)rep(j, 10)if(f[i + 1][j + 1] == 1)isok = false;
        if(isok){
          rep(i, 10){
            rep(j, 9)printf("%d ", res[i + 1][j + 1]);
            printf("%d\n", res[i + 1][j + 1]);
          }
          break;
        }
      }
    }


/*/

//*/ break;
  }
  return 0;
}

C++: #include<stdio.h>

const int N = 10;
int a[N][N];
bool isClick[N][N];

void Click(int x,int y)
{
	int dx[] = {0,1,-1,0, 0,};
	int dy[] = {0,0, 0,1,-1,};
	for(int i = 0;i < 5; ++i)
	{
		if(x+dx[i] >= 0 && x+dx[i] < N && y+dy[i] >= 0 && y+dy[i] < N)
			a[x+dx[i]][y+dy[i]] = !a[x+dx[i]][y+dy[i]];
	}
}

void AllDelete()
{
	int original[N][N];
	int i,j;
	for(i=0;i<N;++i)for(j=0;j<N;++j)original[i][j]=a[i][j];

	unsigned mask=0;
	for(;;)
	{
		for(i=0;i<N;++i)
			for(j=0;j<N;++j)
				a[i][j] = original[i][j],isClick[i][j] = false;
		for(j = 0;j < N;++j)
		{
			if(mask & (1<<j))
				Click(0,j), isClick[0][j] = true;
		}
		++mask;
		for(i = 1; i < N; ++i)
			for(j = 0; j < N; ++j)
			{
				if(a[i-1][j])
					Click(i,j), isClick[i][j] = true;
			}
		bool isEnd = true;
		for(j = 0; j < N; ++j)
		{
			if(a[N-1][j]) isEnd = false;
		}
		if(isEnd) return;
	}
}

int main(void)
{
	int n,i,j;
	scanf("%d",&n);
	while(n--)
	{
		for(i=0;i<N;++i)
			for(j=0;j<N;++j)
			{
				scanf("%d",&a[i][j]);
				isClick[i][j] = false;
			}

		AllDelete();
		for(i=0;i<N;++i)
		{
			for(j=0;j<N;++j)
				printf("%s%d%s",(j?" ":""),isClick[i][j],(N-j==1?"\n":""));
		}
	}
	return 0;
}

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

const int all = (1 << 10) - 1;

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

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

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

		conv[line] = (m >> 1) & all;
	}

	int n;
	cin >> n;

	for(int t=0;t<n;++t){
		for(int y=0;y<10;++y){
			int m = 0;
			for(int x=0;x<10;++x){
				cin >> board[y][x];
			}
			for(int x=0;x<10;++x){
				m = (m << 1) + board[y][x];
			}
			mask[y] = m;
		}

		bool found = false;
		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)cout << " ";
					cout << (((m >> x) & 1) ? 1 : 0);
				}
				cout << endl;
			}

			found = true;
			break;
		}

		if(!found)while(true);
	}
	return 0;
}

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

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

int main() {
  int Tc; cin >> Tc;
  
  while(Tc--) {
    
    int arr[10][10];
    int arr2[10][10];
    
    for(int i=0; i<10; i++)
      for(int j=0; j<10; j++)
	cin >> arr[i][j];
    
    bool good = 0;
    for(int I=0; I<(1<<10); I++) {
      memset(arr2, 0, sizeof(arr2));
      bool ok = 1;
      for(int i=0; i<10; i++) {
	for(int j=0; j<10; j++) {
	  
	  if(i == 0) {
	    if((I>>j) & 1) {
	      if(arr[0][j] == 0) {
		arr[0][j] = arr2[0][j] = 1;
	      }
	    }
	  }
	  else {
	    if(arr[i-1][j] == 1) {
	      arr2[i][j] = 1;
	      for(int k=0; k<5; k++) {
		if(i+dy[k]>=0 && i+dy[k]<10 && j+dx[k]>=0 && j+dx[k]<10) {
		  arr[i+dy[k]][j+dx[k]] = 1 - arr[i+dy[k]][j+dx[k]];
		}
	      }
	    }
	  }
	  
	} 
      }
      
      for(int i=0; i<10; i++) {
	if(arr[9][i]) ok = 0;
      }
      if(ok) {
	good = 1;
	break;
      }
    }
    if(good) {
      for(int i=0; i<10; i++) {
	for(int j=0; j<10; j++) {
	  if(j) cout << " ";
	  cout << arr2[i][j];
	}
	cout << endl;
      }
    }
  }
  
  return 0;
}