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<bits/stdc++.h>
#define l(i,n) for(int i=0;i<n;i++)
using namespace std;
bool m[12][12],c[12][12],d[12][12],q;
int main(){int n;cin>>n;l(u,n){l(i,10)l(j,10)cin>>m[i][j];
bool f[10],t[10]={0};for(int p=1;p<=1024;p++){
l(i,10)f[i]=t[i];l(i,10)l(j,10)c[i][j]=m[i][j];l(k,10){l(i,10)
if(f[i]){for(int j=max(0,i-1);j<=min(9,i+1);j++)c[k][j]^=1;c[k+1][i]^=1;}
l(i,10)d[k][i]=f[i];l(i,10)f[i]=c[k][i];}q=0;l(i,10)q|=f[i];
if(!q){l(i,10)l(j,10){if(j)cout<<" ";cout<<d[i][j];}cout<<endl;
break;}l(i,10)if(p%(int)pow(2,i)==0)t[i]^=1;
}}return 0;}

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

using namespace std;

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

int n;
int input[10][10], state[10][10], ans[10][10];

void pass(int y, int x) {
    for (int i=0; i<5; ++i) {
        if (0 <= y + dy[i] && y + dy[i] < 10 && 0 <= x + dx[i] && x + dx[i] < 10) {
            state[y + dy[i]][x + dx[i]] = !state[y + dy[i]][x + dx[i]];
        }
    }
    ans[y][x] = !ans[y][x];
}

int main() {
    cin >> n;
    while (n --) {
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cin >> input[i][j];
            }
        }
        for (int bt=0; bt<(1<<10); ++bt) {
            memcpy(state, input, sizeof(input));
            memset(ans, 0, sizeof(ans));
            for (int j=0; j<10; ++j) {
                if ((bt>>j) & 1) {
                    pass(0, j);
                }
            }
            for (int i=1; i<10; ++i) {
                for (int j=0; j<10; ++j) {
                    if (state[i-1][j] == 1) {
                        pass(i, j);
                    }
                }
            }
            if (accumulate(state[9], state[9] + 10, 0) == 0) break;
        }
        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>
using namespace std;

bool grid[10][10];

void rev(int y,int x){
  int dy[] = {1,0,-1,0,0}, dx[] = {0,1,0,-1,0};

  for(int i=0;i<5;i++){
    int sy = y+dy[i], sx = x+dx[i];
    if(sy<0 || sx<0 || sy>=10 || sx>=10)continue;
    grid[sy][sx] = !grid[sy][sx];
  }
}

int main(){
  int t;
  bool tmp[10][10];
  int ans[10][10];

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

      for(int j=0;j<10;j++){
	if(i&(1<<j)){
	  rev(0,j);
	  ans[0][j] = 1;
	}else ans[0][j] = 0;
      }

      for(int j=1;j<10;j++){
	for(int k=0;k<10;k++){
	  if(grid[j-1][k]){
	    rev(j,k);
	    ans[j][k] = 1;
	  }else ans[j][k] = 0;
	}
      }

      bool f = false;
      for(int j=0;j<10;j++)f |= grid[9][j];
      if(!f)break;
    }

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

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

void solve() {
    auto v = make_v(10, 10, 0);
    auto ans = v;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> v[i][j];
        }
    }
    auto s = v;
    auto flip = [&](int y, int x)  {
        ans[y][x] ^= 1; v[y][x] ^= 1;
        if(y) v[y-1][x] ^= 1;
        if(x) v[y][x-1] ^= 1;
        if(y != 9) v[y+1][x] ^= 1;
        if(x != 9) v[y][x+1] ^= 1;
    };
    for (int i = 0; i < (1 << 10); ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                ans[j][k] = 0;
            }
        }
        v = s;
        for (int j = 0; j < 10; ++j) {
            if(i & (1 << j)) flip(0, j);
        }
        for (int j = 1; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                if(v[j-1][k]) flip(j, k);
            }
        }
        int ok = 1;
        for (int j = 0; j < 10; ++j) {
            if(v[9][j]) ok = 0;
        }
        if(ok){
            for (int j = 0; j < 10; ++j) {
                for (int k = 0; k < 10; ++k) {
                    printf(k ? " %d" : "%d", ans[j][k]);
                }
                puts("");
            }
            return;
        }
    }
}

int main() {
    int n;
    cin >> n;
    while(n--) {
        solve();
    }
    return 0;
}