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>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstring>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

int main(){
    int n;
    cin >> n;
    while(n!=0){
        int bs[10][10]; 
        REP(i,10)REP(j,10)cin >> bs[i][j];
        int flip[10][10]; 
        int ans[10][10]; 
        REP(i,1<<10){
            memset(flip,0,sizeof(flip));
            memset(ans,0,sizeof(ans));
            REP(j,10){
                if((i>>j)&1){
                    ans[0][j]=1;
                    flip[0][j]^=1;
                    if(j-1>=0)flip[0][j-1]^=1;
                    if(j+1<10)flip[0][j+1]^=1;
                    flip[1][j]^=1;
                }
            }
            FOR(y,1,10){
                REP(x,10){
                    if(flip[y-1][x] ^ bs[y-1][x]){
                        ans[y][x]=1;
                        flip[y-1][x]^=1;
                        flip[y][x]^=1;
                        if(x-1>=0)
                            flip[y][x-1]^=1;
                        if(x+1<10)
                            flip[y][x+1]^=1;
                        if(y+1<10)
                            flip[y+1][x]^=1;
                    }
                }
            }

            int flag=1;
            REP(y,10){
                REP(x,10){
                    if(flip[y][x] ^ bs[y][x]){
                        flag=0;
                        y=10;
                        break;
                    }
                }
            }

            if(flag){
                REP(y,10){
                    REP(x,10){
                        cout << ans[y][x]  << (x==9 ? "\n" : " ");
                    }
                }
                break;
            }
        }
        n--;
    }
    return 0;
}

C++: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
vvint vv,tt,ans;
int dd[]={0,1,0,-1,0};
bool check(int y,int x){
	if(0<=y&&y<10&&0<=x&&x<10) return true;
	return false;
}
void foo(int y,int x){
	tt[y][x]=1-tt[y][x];
	rep(i,4){
		if(check(y+dd[i],x+dd[i+1])) tt[y+dd[i]][x+dd[i+1]]=1-tt[y+dd[i]][x+dd[i+1]];
	}
}
void mainmain(){
	int n;
	cin>>n;
	rep(g,n){
		// vvint vv;
		initvv(vv,10,10);
		rep(i,10) rep(j,10) cin>>vv[i][j];
		rep(i,1<<10){
			tt=vv;
			initvv(ans,10,10,0);
			rep(j,10){
				if(i&(1<<j)){
					ans[0][j]=1;
					foo(0,j);
				}
			}
			reep(j,1,10){
				rep(k,10){
					if(tt[j-1][k]==1){
						ans[j][k]=1;
						foo(j,k);
					}
				}
			}
			bool f=true;
			rep(j,10){
				if(tt[9][j]==1){
					f=false;
					break;
				}
			}
			if(f){
				rep(j,10){
					rep(k,10){
						if(k) cout<<" ";
						cout<<ans[j][k];
					}
					cout<<endl;
				}
				break;
			}
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void flip(vvi& a,int i,int j)
{
	int di[]={-1,0,0,0,1};
	int dj[]={0,-1,0,1,0};
	rep(k,5){
		int ni=i+di[k],nj=j+dj[k];
		if(0<=ni && ni<10 && 0<=nj && nj<10)
			a[ni][nj]^=1;
	}
}

int main()
{
	int tc; cin>>tc;
	while(tc--){
		vvi a(10,vi(10));
		rep(i,10) rep(j,10)
			cin>>a[i][j];
		rep(k,1<<10){
			vvi b=a;
			vvi res(10,vi(10));
			rep(i,10)
				if(k&(1<<i)){
					flip(b,0,i);
					res[0][i]=1;
				}
			repi(i,1,10)
				rep(j,10)
					if(b[i-1][j]){
						flip(b,i,j);
						res[i][j]=1;
					}
			int count1=0;
			rep(i,10)
				count1+=count(allof(b[i]),1);
			if(count1==0){
				rep(i,10)
					rep(j,10)
						cout<<res[i][j]<<(j==9?'\n':' ');
				break;
			}
		}
	}
	
	return 0;
}