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

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

int a[10][10];
int grid[10][10];
int res[10][10];

bool ok(int i, int j)
{
	return i >= 0 && j >= 0 && i < 10 && j < 10;
}

void rev(int x, int y)
{
	for (int dir = 0; dir < 5; dir++){
		int nx = x + dx[dir];
		int ny = y + dy[dir];
		if (ok(nx, ny)) grid[nx][ny] ^= 1;
	}
}

void solve()
{
	for (int x = 0; x < (1 << 10); x++){
		memset(res, 0, sizeof(res));
		memcpy((void *)grid, (void *)a, sizeof(grid));
		
		for (int i = 0; i < 10; i++){
			if (x & (1 << i)){
				res[0][i] = 1;
				rev(0, i);
			}
		}
		
		for (int i = 1; i < 10; i++){
			for (int j = 0; j < 10; j++){
				if (grid[i - 1][j]){
					res[i][j] = 1;
					rev(i, j);
				}
			}
		}
		
		int f = 0;
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				f += grid[i][j];
			}
		}
		if (!f) break;
	}
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			if (j) printf(" ");
			printf("%d", res[i][j]);
		}
		puts("");
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	while (n--){
		for (int i = 0; i < 10; i++){
			for (int j = 0; j < 10; j++){
				scanf("%d", &a[i][j]);
			}
		}
		solve();
	}
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef istringstream ISS;
typedef ostringstream OSS;
typedef vector<string> VS;
typedef int INT;
typedef vector<INT> VI;
typedef vector<VI> VVI;
typedef pair <INT, INT> II;
typedef vector <II> VII;

template<class T> ostream& operator << ( ostream& os, vector<T> v ) {
    for ( typename vector<T>::iterator it_i = v.begin(); it_i != v.end(); ++it_i ) {
        os << *it_i << ", ";
    }
    return os;
}


int L[10][10]; 
int F[10][10]; 
int R[10][10];

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

void input() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cin >> L[i][j];
        }
    }
}

bool check( int r, int c ) {
    int b = L[r][c];
    b ^= F[r][c];
    if ( r - 1 >= 0 ) b ^= F[r-1][c];
    if ( r + 1 < 10 ) b ^= F[r+1][c];
    if ( c - 1 >= 0 ) b ^= F[r][c-1];
    if ( c + 1 < 10 ) b ^= F[r][c+1];
    return b == 1;
}

void output() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            cout << F[i][j];
            if ( j + 1 < 10 ) cout << " ";
        }
        cout << endl;
    }
}

void flip( int r, int c ) {
    int b = L[r][c];
    b ^= F[r][c];
    if ( r - 1 >= 0 ) b ^= F[r-1][c];
    if ( r + 1 < 10 ) b ^= F[r+1][c];
    if ( c - 1 >= 0 ) b ^= F[r][c-1];
    if ( c + 1 < 10 ) b ^= F[r][c+1];
    R[r][c] = b;
}

bool check() {
    for ( int i = 0; i < 10; ++ i ) {
        for ( int j = 0; j < 10; ++ j ) {
            if ( R[i][j] ) return false;
        }
    }
    return true;
}

bool solve( int r ) {
    if ( r >= 10 ) {
        for ( int i = 0; i < 10; ++ i ) {
            for ( int j = 0; j < 10; ++ j ) {
                flip( i, j );
            }
        }
        return check();
    }
    if ( r == 0 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            for ( int j = 0; j < 10; ++ j ) {
                F[r][j] = i & ( 1 << j ) ? 1 : 0;
            }
            if ( solve( r + 1 ) ) return true;
        }
    } else if ( r < 10 ) {
        for ( int i = 0; i < (1<<10); ++ i ) {
            for ( int j = 0; j < 10; ++ j ) {
                F[r][j] = i & ( 1 << j ) ? 1 : 0;
            }
            bool flag = true;
            for ( int j = 0; j < 10; ++ j ) {
                if ( check( r - 1, j ) ) flag = false;
            }
            if ( flag && solve( r + 1 ) ) return true;
        }
    }

    return false;
}

int main() {
    int n;
    while ( cin >> n ) {
        for ( int i = 0; i < n; ++ i ) {
            init();
            input();
            solve( 0 );
            output();
        }
    }
    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) valid&=(t[9][i]==0);

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

			break;
		}

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