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

#define MAX 12

using namespace std;

inline bool inRange(int t, int min, int max){
	return (min <= t && t < max);
}

class CMap{
public:
	int m[MAX][MAX];

	CMap()
	{
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void Reset(){
		for(int i = 0; i < MAX; ++i)
			for(int j = 0; j < MAX; ++j)
				m[i][j] = 0;
	}

	void PassParticle(int i, int j)
	{
		const int di[] = {0,-1,0,1,0};
		const int dj[] = {0,0,1,0,-1};

		for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
			if( inRange( i+di[k], 1, MAX - 1 ) && inRange( j + dj[k], 1, MAX - 1 ) )
				m[i+di[k]][j+dj[k]] = (m[i+di[k]][j+dj[k]] + 1) % 2;
	}

	bool NoLight() const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( m[i][j] == 1 ) return false;
		return true;
	}

	void Print() const
	{
		for(int i = 1; i < MAX - 1; ++i){
			cout << m[i][1];
			for(int j = 2; j < MAX - 1; ++j)
				cout << ' ' << m[i][j];
			cout << '\n';
		}
	}
	
	bool operator==(const CMap &t) const
	{
		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1; ++j)
				if( t.m[i][j] != m[i][j] )
					return false;
		return true;
	}
};

void BFS(CMap &stm, CMap &ret){
	vector< CMap > q;

	q.push_back( stm );

	while( !q.empty() ){
		CMap M = q[0];
		q.erase( q.begin() );

		if( M.NoLight() )
		{
			ret = M;
			break;
		}

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				CMap add;
				int cnt1 = 0;
				const int di[] = {0,-1,0,1,0};
				const int dj[] = {0,0,1,0,-1};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
					if( M.m[i+di[k]][j+dj[k]] == 1 )
						++cnt1;

				if( cnt1 >= 3 )
				{
					add = M;
					add.PassParticle( i, j );
					if( q.end() == find( q.begin(), q.end(), add ) )
						q.push_back( add );
				}
			}
		}
	}
}
void DetermineShootingPoints(CMap &stm, CMap &ans){
	while( !stm.NoLight() ){
		int max1 = 0;
		int pi, pj;

		for(int i = 1; i < MAX - 1; ++i){
			for(int j = 1; j < MAX - 1 ; ++j){
				int cnt1 = 0;
				const int di[] = {0,-1,0,1,0/*-1,-1,0,1, 1, 1, 0,-1*/};
				const int dj[] = {0,0,1,0,-1/* 0, 1,1,1,-0,-1,-1,-1*/};

				for(int k = 0; k < sizeof(di)/sizeof(*di); ++k)
					if( stm.m[i+di[k]][j+dj[k]] == 1 )
						++cnt1;

				if( cnt1 == 5 ){
					stm.PassParticle( i, j );
					ans.m[i][j] = 1;
					goto RETRY;
				}

				if( cnt1 > max1 ){
					max1 = cnt1;
					pi = i;
					pj = j;
				}
			}
		}
		stm.PassParticle( pi, pj );
		ans.m[pi][pj] = 1;
RETRY:;
	}
}
int main(void){
	int n;

	cin >> n;
	for( int D = 0; D < n; ++D )
	{
		CMap M;
		CMap Answer;

		for(int i = 1; i < MAX - 1; ++i)
			for(int j = 1; j < MAX - 1 ; ++j)
				cin >> M.m[i][j];

		//Answer.Reset();
		DetermineShootingPoints( M, Answer );
		Answer.Print();
	}
	return 0;
}

C++: #include <vector>
#include <iostream>
#include <list>

std::list<int> dfs(std::vector<std::vector<bool>> &state, const int &idx = 1) {
	if (idx < 10) {
		int res = 0;
		for (auto i = 0; i < 10; ++i) {
			res <<= 1;
			if (state.at(idx - 1).at(i)) {
				res += 1;
				for (const auto &index : { i - 1, i, i + 1 }) {
					if (index >= 0 && index < 10) {
						state.at(idx).at(index) = !state.at(idx).at(index);
					}
				}
				if (idx != 9) {
					state.at(idx + 1).at(i) = !state.at(idx + 1).at(i);
				}
			}
		}
		auto list = dfs(state, idx + 1);
		if (list.size() + idx == 9) {
			list.push_front(res);
			return list;
		}
		else {
			return list;
		}
	}
	else {
		bool is_on = false;
		for (const auto &cell : state.at(9)) {
			is_on = is_on || cell;
		}
		if (is_on) {
			return std::list<int>{0};
		}
		else {
			return std::list<int>{};
		}
	}
}
std::list<int> solve(std::vector<std::vector<bool>> &state) {
	for (auto i = 0; i < 1023; ++i) {
		auto copy = state;
		for (auto j = 0; j < 10; ++j) {
			if ((i & (1 << j)) != 0) {
				for (const auto &idx : { j - 1, j, j + 1 }) {
					if (idx >= 0 && idx < 10) {
						copy.at(0).at(idx) = !copy.at(0).at(idx);
					}
				}
				copy.at(1).at(j) = !copy.at(1).at(j);
			}
		}
		auto list = dfs(copy);
		if (list.size() == 9) {
			list.push_front(i);
			return list;
		}
	}
	return std::list<int>{};
}
int main() {
	int n;
	for (std::cin >> n; n > 0; --n) {
		std::vector<std::vector<bool>> state(10, std::vector<bool>(10, false));
		bool input;
		for (auto &line : state) {
			for (auto i = 0; i < 10; ++i) {
				std::cin >> input;
				state.at(0).at(i) = input;
			}
		}
		auto res = solve(state);
		for (const auto &line : res) {
			for (auto i = 512; i > 0; i >>= 1) {
				std::cout << static_cast<int>((i & (line)) != 0) << ((i != 1) ? ' ' : '\n');
			}
		}
	}
	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,10)
	{
		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(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));
		memset(temp,0,sizeof(temp));

		rep(j,10)
		{
			rep(k,10)
			{
				cin >> f[j][k];
			}
		}
		
		dfs(0,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;
}