using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Puzzle
    {
        readonly int[] moveX = new int[] { 0, -1, 0, 1 };
        readonly int[] moveY = new int[] { 0, 0, 1, 0 };

        int[,] map, state, ans;

        public void Solve(int[,] map)
        {
            this.map = map;
            state = new int[10, 10];

            DFS(0);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < 10; i++)
            {
                for (int j = 0; j < 10; j++)
                {
                    if (j != 0) sb.Append(" ");

                    sb.Append(ans[i, j]);
                }
                sb.Append("\n");
            }
            Console.Write(sb);
        }

        private void DFS(int depth)
        {
            if (depth == 10)
            {
                if (CheckClear()) ans = (int[,])state.Clone();
                return;
            }

            for (int i = 0; i < 2; i++)
            {
                state[0, depth] = i;

                for (int j = 0; j < 4; j++)
                {
                    int x = moveX[j] + depth;
                    int y = moveY[j];

                    if (!IsValid(x, y)) continue;

                    map[y, x] = map[y, x] == i ? 0 : 1;
                }

                DFS(depth + 1);

                for (int j = 0; j < 4; j++)
                {
                    int x = moveX[j] + depth;
                    int y = moveY[j];

                    if (!IsValid(x, y)) continue;

                    map[y, x] = map[y, x] == i ? 0 : 1;
                }
            }
        }

        private bool CheckClear()
        {
            int[,] temp = (int[,])map.Clone();

            for (int i = 1; i < 10; i++)
            {
                if (i == 2)
                {
                    for (int j = 0; j < 10; j++)
                    {
                        if (temp[0, j] == 1) return false;
                    }
                }

                for (int j = 0; j < 10; j++)
                {
                    if (temp[i - 1, j] == 1)
                    {
                        state[i, j] = 1;
                        temp[i - 1, j] = 0;

                        for (int k = 0; k < 4; k++)
                        {
                            int x = j + moveX[k];
                            int y = i + moveY[k];

                            if (!IsValid(x, y)) continue;

                            temp[y, x] = temp[y, x] == 1 ? 0 : 1;
                        }
                    }
                    else
                    {
                        state[i, j] = 0;
                    }
                }
            }

            for (int i = 0; i < 10; i++)
            {
                if (temp[9, i] == 1) return false;
            }
            return true;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0) return false;
            if (x > 9) return false;
            if (y < 0) return false;
            if (y > 9) return false;
            return true;
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Puzzle pz = new Puzzle();

            while (n-- > 0)
            {
                int[,] map = new int[10, 10];

                for (int i = 0; i < 10; i++)
                {
                    int[] input = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

                    for (int j = 0; j < 10; j++)
                    {
                        map[i, j] = input[j];
                    }
                }
                pz.Solve(map);
            }
        }
    }
}

Measured memory_bytes: 9344