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>

using namespace std;

char inputs[10][10];
char tmp[10][10];
char ans[10][10];
int dx[] = {0, 1, 0, -1, 0};
int dy[] = {-1, 0, 1, 0, 0};

void through(int y, int x){
  ans[y][x] = '1';
  for(int i=0;i<5;i++){
    int ty = y + dy[i];
    int tx = x + dx[i];
    if(ty<0 || ty>=10) continue;
    if(tx<0 || tx>=10) continue;
    if(tmp[ty][tx] == '1')tmp[ty][tx] = '0';
    else tmp[ty][tx] = '1';
  }
}

bool check(){
  for(int i=1;i<10;i++){
    for(int j=0;j<10;j++){
      if(tmp[i-1][j] == '1') through(i, j);
    }
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      if(tmp[i][j] == '1') return false;
    }
  }
  return true;
}

main(){
  int t;
  cin >> t;
  for(int tc=1;tc<=t;tc++){
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	cin >> inputs[i][j];
      }
    }
    for(int i=0;i<(1<<10);i++){
      fill(ans[0], ans[10], '0');
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++){
 	  tmp[j][k] = inputs[j][k];
	}
      }
      for(int j=0;j<10;j++){
	if(i & (1<<j)) through(0, j);
      }
      /*for(int j=0;j<10;j++){
	cout << ans[0][j];
	}cout << endl;*/
      if(check()) break;
    }
    for(int i=0;i<10;i++){
      cout << ans[i][0];
      for(int j=1;j<10;j++){
	cout << ' ' << 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;
	bool fir=true;
	while(n--){
		if(!fir)cout<<endl;
		int panel[10]={},ans[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?????????
			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)ans[j+1]|=1<<k;
				}
			}
			if(ans[9]==0){
				for(int i=0;i<10;i++){
					for(int j=0;j<10;j++){
						int tmp=(ans[i]>>j)&1;
						printf(j==9?"%d\n":"%d ",tmp);
					}
				}		
				break;
			}
		}
		fir=false;
	}
    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;

int t[102][102], tt[102][102];
int ans[102][102];

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

bool solve(int bit){
  memcpy(t, tt, sizeof(tt));
  memset(ans, 0, sizeof(ans));

  for(int i = 0; i < 10; i++){
    if(bit & (1 << i)){
      ans[0][i] = true;

      for(int j = 0; j < 4; j++){
        int nx = i + dx[j];
        int ny = dy[j];
        if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
        t[ny][nx] = !t[ny][nx];
      }
    }
  }

  for(int i = 1; i < 10; i++){
    for(int j = 0; j < 10; j++){
      if(t[i - 1][j]){
        ans[i][j] = true;

        for(int k = 0; k < 4; k++){
          int nx = j + dx[k];
          int ny = i + dy[k];
          if(nx < 0 || 10 <= nx || ny < 0 || 10 <= ny) continue;
          t[ny][nx] = !t[ny][nx];
        }
      }
    }
  }

  for(int i = 0; i < 10; i++){
    if(t[9][i]){
      return false;
    }
  }

  return true;
}

int main(){
  int T;
  cin >> T;

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

    for(int bit = 0; bit < (1 << 10); bit++){
      bool flg = solve(bit);

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

        break;
      }
    }
  }
}

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];
	assert(ans[i][j]==0||ans[i][j]==1);
      }
      cout <<endl;
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>

using namespace std;

#define reep(i,f,t) for(int i=f ; i<int(t) ; ++i)
#define rep(i,n) reep(i, 0, n) 

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

void push(int light[10][10], int y, int x)
{
	const int dy[] = {-1, 0, 0, 0, 1};
	const int dx[] = {0, -1, 0, 1, 0};

	rep(i, 5){
		int py = y + dy[i];
		int px = x + dx[i];
		if(py<0 || 10<=py || px<0 || 10<=px)
			continue;
		light[py][px] = !light[py][px];
	}
}

void simulate(int tmp[10][10], int j, bool output)
{
	rep(k, 10){
		if((j>>k)&1){
			push(tmp, 0, k);
			if(output)
				printf("%s1", k?" ":"");
		}else if(output)
			printf("%s0", k?" ":"");
	}
	if(output)
		puts("");

	rep(k, 9){
		rep(l, 10){
			if(tmp[k][l]){
				push(tmp, k+1, l);
				if(output)
					printf("%s1", l?" ":"");
			}else if(output)
				printf("%s0", l?" ":"");
		}
		if(output)
			puts("");
	}
}

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		int light[10][10];
		rep(j, 10) rep(k, 10)
			scanf("%d", &light[j][k]);

		rep(j, 1<<10){
			int tmp[10][10];
			rep(k, 10) rep(l, 10)
				tmp[k][l] = light[k][l];

			simulate(tmp, j, false);
			bool ok = true;
			rep(k, 10) rep(l, 10){
				if(tmp[k][l]){
					ok = false;
					k=10;
					break;
				}
			}

			if(ok){
				simulate(light, j, true);
				break;
			}
		}
	}

	return 0;
}