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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

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

void reverse(vector<vint>& board, int x, int y)
{
	rep(i, 5)
	{
		int nx = x + dx[i], ny = y + dy[i];
		
		if(0 <= nx && nx < 10 && 0 <= ny && ny < 10)
			board[nx][ny] = !board[nx][ny];
	}
}


void bitinitialize(vector<vint>& board, vector<vint>& ans, int bit)
{
	rep(i, 10) if(bit & 1 << i)
	{
		reverse(board, i, 0);
		ans[i][0] = 1;
	}
}


void fill(vector<vint>& board, vector<vint>& ans)
{
	REP(y, 1, 10) rep(x, 10)
	{
		if(board[x][y-1])
		{
			reverse(board, x, y);
			ans[x][y] = 1;
		}
	}
}


bool check(vector<vint>& board)
{
	rep(i, 10) rep(j, 10)
		if(board[i][j]) return false;
	
	return true;
}


int main()
{
    int n;
	cin >> n;
	
	while(n--)
	{
		vector<vint> answer(10, vint(10));
		
		rep(y, 10) rep(x, 10)
			cin >> answer[x][y];
		
		rep(bit, 1 << 10)
		{
			vector<vint> board(answer);
			vector<vint> ans(10, vint(10, 0));
			
			bitinitialize(board, ans, bit);
			
			fill(board, ans);
						
			if(check(board))
			{
				rep(y, 10) rep(x, 10)
					cout << ans[x][y] << (x == 9 ? "\n" : " ");
				
				break;
			}
		}
	}
}

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]={};
		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;
			}
		}
		fir=false;
	}
    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() {
    ios::sync_with_stdio(false);
    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>
#include <cstring>
using namespace std;

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

int ori[10][10];
int arr[10][10];
int arr2[10][10];
    
void flip(int i, int j) {
  arr[i][j] = 1 - arr[i][j];
  arr2[i][j] = 1 - arr2[i][j];
  for(int k=0; k<4; k++) {
    int nx = j+dx[k], ny = i+dy[k];
    if(0<=ny && ny<10 && 0<=nx && nx<10) {
      arr[ny][nx] = 1 - arr[ny][nx];
    }
  }
}

int main() {
  int Tc; cin >> Tc;
  
  while(Tc--) {
    
    for(int i=0; i<10; i++)
      for(int j=0; j<10; j++)
	cin >> ori[i][j];
    
    bool good = 0;
    for(int I=0; I<(1<<10); I++) {
      memset(arr2, 0, sizeof(arr2));
      memcpy(arr, ori, sizeof(ori));
      bool ok = 1;
      for(int i=0; i<10; i++) {
	for(int j=0; j<10; j++) {
	  
	  if(i == 0) {
	    if((I>>j) & 1) {
	      if(arr[0][j] == 0) flip(0, j);
	    }
          }
	  else {
	    if(arr[i-1][j] == 1) flip(i, j);
	  }
	  
	} 
      }
      
      for(int i=0; i<10; i++) {
	if(arr[9][i]) ok = 0;
      }
      if(ok) {
	good = 1;
	break;
      }
    }
    if(good) {
      for(int i=0; i<10; i++) {
	for(int j=0; j<10; j++) {
	  if(j) cout << " ";
	  cout << arr2[i][j];
	}
	cout << endl;
      }
    }
  }
  
  return 0;
}