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++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}


	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (double k) { return Point(x * k, y * k); }
	Point operator / (double k) { return Point(x / k, y / k); }
	bool operator < (const Point &p)const { return x != p.x ? x < p.x : y < p.y; }
	bool operator ==(const Point &p)const { return fabs(x - p.x) < EPS&&fabs(y - p.y) < EPS; }

	double abs() { return sqrt(norm()); }
	double norm() { return x*x + y*y; }
};
typedef Point Vector;
struct Segment
{
	Point p1, p2;
};
typedef Segment Line;
class Circle
{
public:
	Point c;
	double r;
	Circle(Point c = Point(), double r = 0.0) :c(c), r(r) {}
};

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }//??????
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }//??????
bool isOrthogonal(Vector a, Vector b) { return fabs(dot(a, b)) < EPS; }//??´??????
bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) { return isOrthogonal(a1 - a2, b1 - b2); }
bool isOrthogonal(Line l1, Line l2) { return fabs(dot(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
bool isParallel(Vector a, Vector b) { return fabs(cross(a, b)) < EPS; }//?????????
bool isParallel(Point a1, Point a2, Point b1, Point b2) { return isParallel(a1 - a2, b1 - b2); }
bool isParallel(Line l1, Line l2) { return fabs(cross(l1.p2 - l1.p1, l2.p2 - l2.p1)) < EPS; }
Point project(Line s, Point p)
{
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base*r;
}


int dx[5] = { 0,-1,0,1,0 }, dy[5] = { 1,0,0,0,-1 };
bool check(int a[12][12])
{
	int t = 0;
	for (int i = 1; i <= 10; i++)for (int j = 1; j <= 10; j++)t += a[i][j];
	return t == 0;
}
void paint(int f[12][12], int x, int y)
{
	for (int k = 0; k < 5; k++)
	{
		f[x + dx[k]][y + dy[k]]++;
		f[x + dx[k]][y + dy[k]] %= 2;
	}
}
int main()
{
	int n; cin >> n;
	while (n--)
	{
		int a[12][12] = {};
		bool ans[12][12] = {};
		for (int i = 1; i <= 10; i++)
		{
			for (int j = 1; j <= 10; j++)
			{
				cin >> a[i][j];
			}
		}
		for (int c = 0; c < 1024; c++)
		{
			int f[12][12];
			memset(ans, 0, sizeof ans);
			for (int i = 0; i < 12; i++)for (int j = 0; j < 12; j++)f[i][j] = a[i][j];
			bitset<10> b(c);
			for (int i = 1; i <= 10; i++)
			{
				ans[1][i] = b[i - 1];
				if (b[i - 1])
				{
					paint(f, 1, i);
				}
			}
			for (int i = 2; i <= 10; i++)
			{
				for (int j = 1; j <= 10; j++)
				{
					if (f[i - 1][j])
					{
						paint(f, i, j);
						ans[i][j] = true;
					}
				}
			}
			if (check(f))break;
		}
		for (int i = 1; i <= 10; i++)
		{
			for (int j = 1; j <= 10; j++)
			{
				cout << ans[i][j];
				if (j != 10)cout << " ";
			}
			cout << endl;
		}
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <fstream>
#include <sstream>
#include <math.h>
#include <queue>
#include <stack>
#include <math.h>
#include <string.h>


using namespace std;


void f(bool box[12][12]){
    for(int i=1; i<=10; i++){
        for(int j=1; j<=10; j++){
            cout<<box[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}

int main(){
    int n;
    while(cin>>n){
        
        bool box[12][12]={0};
        
        for(int i=1; i<=10; i++){
            for(int j=1; j<=10; j++){
                cin>>box[i][j];
            }
        }
        //cout<<"----------------------"<<endl;
        
        bool box2[12][12]={0};

        for(int i=0; i<(1<<10 - 1); i++){
            memcpy(box2, box, sizeof(box));
            int l[12][12]={0};
            for(int j=1; j<=10; j++){
                l[0][j]= (i>>j)%2;
            }
            
            for(int j=1; j<=10; j++){
                for(int k=1; k<=10; k++){
                    if(l[j-1][k]==1){
                        box2[j][k]=(box2[j][k]+1)%2;
                        box2[j][k+1]=(box2[j][k+1]+1)%2;
                        box2[j][k-1]=(box2[j][k-1]+1)%2;
                        box2[j-1][k]=(box2[j-1][k]+1)%2;
                        box2[j+1][k]=(box2[j+1][k]+1)%2;
                    }
                }
                
                for(int k=1; k<=10; k++){
                    l[j][k]=box2[j][k];
                }
            }
            
            bool end_flag=true;
            for(int i=1; i<=10; i++){
                if(l[10][i]==1){
                    end_flag=false;
                    break;
                }
            }
            
            
            if(end_flag){
                for(int i=1; i<=10; i++){
                    for(int j=1; j<=10; j++){
                        cout<<l[i][j];
                        if(j==10)break;
                        cout<<" ";
                    }
                    cout<<endl;
                }
                break;
            }
        }
        //cout<<"============================"<<endl;

        
        
    }
}