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

namespace ConsoleApplication1
{
    struct Position
    {
        internal int x, y;

        public Position(int x, int y)
        {
            this.x = x;
            this.y = y;
        }
    }

    class Puzzle
    {
        struct State
        {
            internal Position pos;
            internal int[,] map;
            internal List<Position> log;
        }

        State start;

        public void Solve(int[,] map)
        {
            start.pos = new Position(0, 0);
            start.map = map;
            start.log = new List<Position>();

            List<Position> res = Solve();

            int[,] resMap = new int[10, 10];

            foreach (var p in res)
            {
                resMap[p.y, p.x] = 1;
            }

            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(resMap[i, j]);
                }
                sb.Append("\n");
            }
            Console.Write(sb);
        }

        private List<Position> Solve()
        {
            Stack<State> stk = new Stack<State>();
            stk.Push(start);

            while (stk.Count > 0)
            {
                State cur = stk.Pop();

                if (CheckClear(cur.map)) return cur.log;

                if (cur.pos.y == 10) continue;

                State next;
                next.pos.x = cur.pos.x + 1;
                next.pos.y = cur.pos.y;

                if (next.pos.x == 10)
                {
                    next.pos.x = 0;
                    next.pos.y++;
                }

                bool isPush = false;
                bool isKeep = false;

                if (cur.pos.y == 0)
                {
                    isPush = true;
                    isKeep = true;
                }
                else
                {
                    isPush = (cur.map[cur.pos.y - 1, cur.pos.x] == 1);
                    isKeep = !isPush;
                }

                if (isPush)
                {
                    next.map = (int[,])cur.map.Clone();
                    Reverse(cur.pos, next.map);
                    next.log = new List<Position>(cur.log);
                    next.log.Add(cur.pos);
                    stk.Push(next);
                }

                if (isKeep)
                {
                    next.map = cur.map;
                    next.log = cur.log;
                    stk.Push(next);
                }
            }
            return null;
        }

        private bool CheckClear(int[,] map)
        {
            foreach (var m in map)
            {
                if (m == 1) return false;
            }
            return true;
        }

        private void Reverse(Position pos, int[,] map)
        {
            map[pos.y, pos.x] = map[pos.y, pos.x] == 0 ? 1 : 0;
            if (pos.x > 0) map[pos.y, pos.x - 1] = map[pos.y, pos.x - 1] == 0 ? 1 : 0;
            if (pos.x < 9) map[pos.y, pos.x + 1] = map[pos.y, pos.x + 1] == 0 ? 1 : 0;
            if (pos.y > 0) map[pos.y - 1, pos.x] = map[pos.y - 1, pos.x] == 0 ? 1 : 0;
            if (pos.y < 9) map[pos.y + 1, pos.x] = map[pos.y + 1, pos.x] == 0 ? 1 : 0;
        }
    }

    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: 10608