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 <cstring>
using namespace std;

class Board
{
public:
	Board()
	{
		memset( m_board, 0, sizeof(m_board) );
	}
	~Board()
	{
	}

	void input()
	{
		for( int i = 1; i < 11; ++i ){
			int bits = 0;
			for( int j = 0; j < 10; ++j ){
				bits <<= 1;
				int n;
				cin >> n;
				bits |= n;
			}
			m_board[ i ] = bits;
		}
	}
	void output()
	{
		for( int i = 0; i < 10; ++i ){
			int bit = 1 << 9;
			bool first = true;
			for( int j = 0; j < 10; ++j ){
				if( first ){
					first = false;
				}else{
					cout << " ";
				}
				cout << ( m_correct[ i ] & bit ? 1 : 0 );
				bit >>= 1;
			}
			cout << endl;
		}
	}
	bool light( int bits )
	{
		memset( m_correct, 0, sizeof(m_correct) );
		int board[ 12 ];
		memcpy( board, m_board, sizeof(m_board) );

		int mask = ( 1 << 10 ) - 1;
		for( int i = 1; i < 11; ++i ){
			m_correct[ i - 1 ] = bits;

			board[ i - 1 ] ^= bits; board[ i - 1 ] &= mask;
			board[ i + 1 ] ^= bits; board[ i + 1 ] &= mask;

			board[ i ] ^= bits;
			board[ i ] ^= ( bits << 1 );
			board[ i ] ^= ( bits >> 1 );
			board[ i ] &= mask;
			if( i > 1 && board[ i - 1 ] != 0 ){
				return false;
			}
			bits = board[ i ];
		}

		return board[ 10 ] == 0;
	}

private:
	int m_board[ 12 ];
	int m_correct[ 10 ];
};

int main()
{
	int n;

	while( cin >> n ){
		for( int i = 0; i < n; ++i ){
			Board board;
			board.input();

			for( int j = 0; j < ( 1 << 10 ); ++j ){
				if( board.light( j ) ){
					board.output();
					break;
				}
			}
		}
	}
	return 0;
}

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


void mark(int mp[10][10],int y,int x){
  int dx[]={0,0,1,-1},dy[]={1,-1,0,0};
  for(int i=0;i<4;i++) {
    int nx=x+dx[i],ny=y+dy[i];
    if(nx<0||ny<0||nx>=10||ny>=10)continue;
    mp[ny][nx]=!mp[ny][nx];
  }
  mp[y][x]=!mp[y][x];
}

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

int main(){
  int q;
  cin>>q;
  while(q--){
    int mp[10][10];
    for(int i=0;i<10;i++)for(int j=0;j<10;j++)cin>>mp[i][j];

    int ans[10][10]={};
    for(int i=0;i<(1<<10)&&!check(mp);i++){
      for(int j=0;j<10;j++)if((ans[0][j]=((i>>j)%2)))mark(mp,0,j);

      for(int j=1;j<10;j++)
	for(int k=0;k<10;k++)
	  if((ans[j][k]=mp[j-1][k]))mark(mp,j,k);
    }

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

  }

  return 0;
}

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;
				int cnt_valid = 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( inRange( i+di[k], 1, MAX - 1) && inRange( j+dj[k], 1, MAX-1 ) )
						++cnt_valid;
				}


				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;
				int cnt_valid = 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( inRange( i+di[k], 1, MAX - 1) && inRange( j+dj[k], 1, MAX-1 ) )
						++cnt_valid;
				}

				if( cnt1 == cnt_valid ){
					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;
}