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 <algorithm>
#define SIZE 10
using namespace std;

class State{
public:
  int data[SIZE][SIZE];
  int put[SIZE][SIZE];
  State() {
    fill((int*)put, (int*)put+SIZE*SIZE, 0);
  }
  void puts(int x, int y) {
    static int d[5][2] = {{0,-1},{1,0},{0,1},{-1,0},{0,0}};
    put[y][x] = 1;
    for(int k = 0; k < 5; k++) {
      int nx = x + d[k][0];
      int ny = y + d[k][1];
      if(nx < 0 || nx >= SIZE) continue;
      if(ny < 0 || ny >= SIZE) continue;
      data[ny][nx] = -(data[ny][nx] - 1);
    }
  }
  bool isAll0() {
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	if(data[i][j] != 0) return false;
      }
    }
    return true;
  }
  void show() {
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	cout << put[i][j];
      }
      cout << endl;
    }
  }
};

bool rec(State s, int x, int y) {
  static int d[5][2] = {{0,-1},{1,0},{0,1},{-1,0},{0,0}};
  if(s.isAll0()) {
    s.show();
    return true;
  }

  for(int i = y; i < SIZE; i++) {
    for(int j = x; j < SIZE; j++) {
      bool flag = false;
      for(int k = 0; k < 5; k++) {
	int nx = j + d[k][0];
	int ny = i + d[k][1];
	if(nx < 0 || nx >= SIZE) continue;
	if(ny < 0 || ny >= SIZE) continue;
	if(s.data[ny][nx] == 1) {
	  flag = true;
	  break;
	}
      }
      flag = true;
      if(flag) {
	if(i > 0 && s.data[i-1][j] == 0) continue;
	State tmp = s;
	tmp.puts(j, i);
	int nx, ny;
	nx = j + 1;
	ny = i;
	if(nx >= SIZE) {
	  nx = 0;
	  ny++;
	}
	if(rec(tmp, nx, ny)) {
	  return true;
	}
	if(i > 0 && s.data[i-1][j] == 1) return false;
      }
    }
  }
  return false;
}

main() {
  int n;
  cin >> n;
  for(int t = 0; t < n; t++) {
    State s;
    for(int i = 0; i < SIZE; i++) {
      for(int j = 0; j < SIZE; j++) {
	cin >> s.data[i][j];
      }
    }
    rec(s, 0, 0);
  }
}

C++: #include <iostream>
#include <cstring>

using namespace std;

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

int main() {
    int n;
    cin >> n;
    int state[10][10];
    int ans[10][10];
    while (n --) {
        memset(state, 0, sizeof(state));
        memset(ans, 0, sizeof(ans));
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cin >> state[i][j];
            }
        }
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][j] == 1) {
                    state[i][j] = 1 - state[i][j];
                    if (valid(i+1, j-1)) state[i+1][j-1] = 1 - state[i+1][j-1];
                    if (valid(i+1, j))   state[i+1][j]   = 1 - state[i+1][j];
                    if (valid(i+1, j+1)) state[i+1][j+1] = 1 - state[i+1][j+1];
                    if (valid(i+2, j))   state[i+2][j]   = 1 - state[i+2][j];
                    ans[i+1][j] = 1;
                }
            }
        }
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}

C++: #include <iostream>
#include <stdio.h>
#include <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int dx[]={-1,0,0,1};
int dy[]={0,0,-1,0};
int main()
{
    int n;
	cin>>n;
	while(n--){
		int panel[10]={};
		for(int i=0;i<10;i++){
			for(int j=0;j<10;j++){
				int tmp;
				cin>>tmp;
				panel[i]|=tmp<<j;
			}
		}
		for(int i=0;i<(1<<10);i++){//1??????ans?????????
			int ans[10]={};
			ans[0]=i;
			for(int j=0;j<9;j++){//????????????ans????¨????
				for(int k=0;k<10;k++){//?????????????????°???
					int tmp=0;
					for(int l=0;l<4;l++){
						int nx=k+dx[l],ny=j+dy[l];
						if(0<=nx&&nx<10&&0<=ny&&ny<9)tmp+=(ans[ny]>>nx)&1;
					}
					if((tmp+(panel[j]>>k)&1)%2)ans[j+1]|=1<<k;
				}
			}
			int check=ans[8];
			for(int j=0;j<10;j++){
				if((ans[9]>>j)&1){
					for(int k=-1;k<=1;k++){
						int x=j+k;
						if(0<=x&&x<10){
							if((check>>x)&1)check&=~(1<<x);
							else check|=1<<x;
						}
					}
				}
			}
			if(check==panel[9]){
				for(int y=0;y<10;y++){
					for(int x=0;x<10;x++){
						int tmp=(ans[y]>>x)&1;
						printf(x==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
	}
    return 0;
}

C++: #include <iostream>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>

using namespace std;

bool orig[10][10];
bool work[10][10];
bool ans[10][10];


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

bool debug = false;

void flip(int x, int y){
	for(int i=0;i<5;i++){
		if(0 <= x+dx[i] && x+dx[i] <10 &&
		0 <= y+dy[i] && y+dy[i] < 10){
			work[x+dx[i]][y+dy[i]] = 1 - work[x+dx[i]][y+dy[i]];
		}
	}
	return;
}


int main(void){
	int n;
	int tmp;
	bool isfirst = true;
	string str;
	
	cin >> n;
	cin.ignore();
	
	for(int cas=0;cas<n;cas++){
		memset(orig, false, sizeof(orig));
		
		//if(!isfirst) cout << endl;
		for(int i=0;i<10;i++){
			getline(cin,str);
			istringstream iss(str);
			if(debug) cout << i << " " << str << endl;
			for(int j=0;j<10;j++){
				iss >> tmp;
				if(tmp == 0){
					orig[i][j] = false;
				}else{
					orig[i][j] = true;
				}
			}
		}
		
		for(int i=0;i < 1 << 10; i++){
			if(debug) cout << i <<endl;
			
			copy(orig, orig+10*10, work);
			//1sÚÉÎ·é
			for(int j=0;j<10;j++){
				if(i & 1 << j){
					flip(0,j);
					ans[0][j] = true;
				}else{
					ans[0][j] = false;
				}
			}
			
			for(int j=1;j<10;j++){
				for(int k=0;k<10;k++){
					if(work[j-1][k]){
						flip(j,k);
						ans[j][k] = true;
					}else{
						ans[j][k] = false;
					}
				}
			}
			
			//check ended or not
			bool isended = true;
			for(int j=0;j<10;j++){
				for(int k=0;k<10;k++){
					if(work[j][k]){ isended = false;}
				}
			}
			if(isended){
				for(int j=0;j<10;j++){
					for(int k=0;k<10;k++){
						if(k==9){
							cout << ans[j][k] << endl;
						}else{
							cout << ans[j][k] << " ";
						}
					}
				}
				isfirst = false;
				break;
			}
		}
	}
}