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<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int f(int p[][12],int q[][12],int x){
  int i,j;
  int r[12][12],s[12][12];
  if(x==11){
    for(i=2;i<10;i++){
      for(j=1;j<11;j++){
	if(p[j][i]){
	  p[j  ][i  ]=(p[j  ][i  ]+1)%2;
	  p[j-1][i+1]=(p[j-1][i+1]+1)%2;
	  p[j  ][i+1]=(p[j  ][i+1]+1)%2;
	  p[j+1][i+1]=(p[j+1][i+1]+1)%2;
	  p[j  ][i+2]=(p[j  ][i+2]+1)%2;
	  q[j][i+1]=1;
	}
      }
    }
    for(i=1;i<11;i++){
      if(p[i][10])
	break;
    }
    if(i==11){
      for(i=1;i<11;i++){
	for(j=1;j<11;j++)
	  cout<<q[j][i];
	cout<<endl;
      }
      return 1;
    }
  }else if(x==10){
    if(p[x][1]){
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }else{
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      if(f(r,s,x+1))
	return 1;
    }
  }else{
      if(p[x][1]){
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x+1][0]=(r[x+1][0]+1)%2;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x+1][1]=(r[x+1][1]+1)%2;
      r[x+2][1]=(r[x+2][1]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      s[x+1][1]=1;
      if(f(r,s,x+1))
	return 1;
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }else{
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      if(f(r,s,x+1))
	return 1;
      memcpy(r,p,sizeof(r));
      memcpy(s,q,sizeof(s));
      r[x+1][0]=(r[x+1][0]+1)%2;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x+1][1]=(r[x+1][1]+1)%2;
      r[x+2][1]=(r[x+2][1]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      s[x+1][1]=1;
      r[x  ][1]=(r[x  ][1]+1)%2;
      r[x-1][2]=(r[x-1][2]+1)%2;
      r[x  ][2]=(r[x  ][2]+1)%2;
      r[x+1][2]=(r[x+1][2]+1)%2;
      r[x  ][3]=(r[x  ][3]+1)%2;
      s[x  ][2]=1;
      if(f(r,s,x+1))
	return 1;
    }
  }
  return 0;
}
int main(){
  int i,j,k;
  int q[12][12],r[12][12],n;
  int (*p)[12][12];
  cin>>n;
  p=new int[n][12][12];
  for(i=0;i<n;i++)
    for(j=1;j<11;j++)
      for(k=1;k<11;k++)
	cin>>p[i][k][j];
  for(i=0;i<n;i++){
    memcpy(r,&p[i][0][0],sizeof(r));
    memset(q,0,sizeof(q));
    f(r,q,1);
    memcpy(r,&p[i][0][0],sizeof(r));
    memset(q,0,sizeof(q));
    r[1][0]=(r[1][0]+1)%2;
    r[0][1]=(r[0][1]+1)%2;
    r[1][1]=(r[1][1]+1)%2;
    r[2][1]=(r[2][1]+1)%2;
    r[1][2]=(r[1][2]+1)%2;
    q[1][1]=1;
    f(r,q,1);
  }
  delete [] p;
  return 0;
}

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 mask = ( 1 << 10 ) - 1;
		for( int i = 1; i < 11; ++i ){
			m_correct[ i - 1 ] = bits;

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

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

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

int t[10][10],s[10][10],ans[10][10];
int dx[] = {0,-1,0,1,0};
int dy[] = {-1,0,0,0,1};

bool check(int *used){
	memset(ans,0,sizeof(ans));
	memcpy(s,t,sizeof(t));

	for(int i=0;i<10;i++){
		ans[0][i] = used[i];
		if(used[i]){
			for(int j=0;j<5;j++){
				int nx = i + dx[j];
				int ny = dy[j];

				if(nx>=0 && 10>nx && ny>=0 && 10>ny){
					s[ny][nx] = !s[ny][nx];
				}
			}
		}
	}

	for(int i=1;i<10;i++){
		for(int j=0;j<10;j++){
			if(s[i-1][j]){ //ツ湘」ツつェ1ツづ按づァツづ篠必ツつクツ古オツつェツ必ツ要
				ans[i][j] = 1;
				for(int k=0;k<5;k++){
					int nx = j + dx[k];
					int ny = i + dy[k];

					if(nx>=0 && 10>nx && ny>=0 && 10>ny){
						s[ny][nx] = !s[ny][nx];
					}
				}
			}
		}
	}

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

bool solve(int idx,int *used){
	if(idx == 10){
		if(check(used)){
			return true;
		}
		return false;
	}

	if(solve(idx+1,used)) return true;
	used[idx] = 1;
	if(solve(idx+1,used)) return true;
	used[idx] = 0;

	return false;
}

int main(void){
	int n;
	cin>>n;

	while(n--){
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				cin>>t[i][j];
			}
		}

		int used[10];
		memset(used,0,sizeof(used));
		solve(0,used);

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

	return 0;
}