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 <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>
#include <cstring>

using namespace std;

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

int state[10][10];
int 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]] = 1 - state[y + dy[i]][x + dx[i]];
        }
    }
    ans[y][x] = 1 - ans[y][x];
}

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int j=0; j<10; ++j) {
            if ((bt>>j) % 10 == 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);
                }
            }
        }
        bool ok = true;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                if (state[i][j] == 1) ok = false;
            }
        }
        if (ok) return ;
    }
}

int main() {
    int n;
    cin >> n;
    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];
            }
        }
        solve();
        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;

int state[10][10];
int ans[10][10];

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

void solve() {
    for (int bt=0; bt<(1<<10); ++bt) {
        for (int j=0; j<10; ++j) {
            if ((bt>>j) % 10 == 1) {
                state[0][j] = 1 - state[0][j];
                if (valid(1, j-1)) state[1][j-1] = 1 - state[1][j-1];
                if (valid(1, j))   state[1][j]   = 1 - state[1][j];
                if (valid(1, j+1)) state[1][j+1] = 1 - state[1][j+1];
                if (valid(2, j))   state[2][j]   = 1 - state[2][j];
                ans[0][j] = 1;
            }
        }
        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];
                    if (valid(i+1, j))   ans[i+1][j] = 1 - ans[i+1][j];
                }
            }
        }
        bool ok = true;
        for (int j=0; j<10; ++j) {
            if (state[9][j] == 1) ok = false;
        }
        if (ok) return ;
    }
}

int main() {
    int n;
    cin >> n;
    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];
            }
        }
        solve();
        cout << "ans:" << endl;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << ans[i][j];
            }
            cout << endl;
        }
        cout << "state:" << endl;
        for (int i=0; i<10; ++i) {
            for (int j=0; j<10; ++j) {
                cout << (j == 0 ? "" : " ") << state[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}