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

namespace ConsoleApplication1
{
    struct Point { internal int x, y; }

    class Blur
    {
        readonly int N = 10;
        readonly int n;

        int[][] map;
        List<string> path, res;

        public Blur(int n)
        {
            this.n = n;

            map = new int[N][];
            path = new List<string>();
        }

        public void MakeMap(int[] source, int i)
        {
            map[i] = (int[])source.Clone();
        }

        public void Solve()
        {
            Point start;
            start.x = 0;
            start.y = 0;

            DFS(start);

            StringBuilder sb = new StringBuilder();
            foreach (var s in res) sb.AppendLine(s);
            Console.Write(sb);
        }

        private void DFS(Point p)
        {
            if (path.Count == n)
            {
                if (CheckMap()) res = new List<string>(path);
                return;
            }

            Point next = SearchNext(p);

            if (next.x < 0) return;

            for (int i = 1; i <= 3; i++)
            {
                if (IsValid(next, i))
                {
                    DrawMap(next, i);

                    if (CheckDraw(next, i)) DFS(next);

                    RevMap(next, i);
                }
            }
        }

        private Point SearchNext(Point p)
        {
            Point ret;
            ret.x = -1;
            ret.y = -1;

            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (map[i][j] == 0) continue;

                    if (map[i][j] > 0)
                    {
                        ret.x = j;
                        ret.y = i;
                        return ret;
                    }
                    else return ret;
                }
            }
            return ret;
        }

        private void DrawMap(Point p, int size)
        {
            Point cp = CenterPos(p, size);

            path.Add(string.Format("{0} {1} {2}", cp.x, cp.y, size));

            map[cp.y][cp.x]--;
            map[cp.y][cp.x - 1]--; map[cp.y][cp.x + 1]--;
            map[cp.y - 1][cp.x]--; map[cp.y + 1][cp.x]--;

            if (size == 1) return;

            map[cp.y - 1][cp.x - 1]--; map[cp.y - 1][cp.x + 1]--;
            map[cp.y + 1][cp.x - 1]--; map[cp.y + 1][cp.x + 1]--;

            if (size == 2) return;

            map[cp.y][cp.x - 2]--; map[cp.y][cp.x + 2]--;
            map[cp.y - 2][cp.x]--; map[cp.y + 2][cp.x]--;
        }

        private void RevMap(Point p, int size)
        {
            Point cp = CenterPos(p, size);

            path.RemoveAt(path.Count - 1);

            map[cp.y][cp.x]++;
            map[cp.y][cp.x - 1]++; map[cp.y][cp.x + 1]++;
            map[cp.y - 1][cp.x]++; map[cp.y + 1][cp.x]++;

            if (size == 1) return;

            map[cp.y - 1][cp.x - 1]++; map[cp.y - 1][cp.x + 1]++;
            map[cp.y + 1][cp.x - 1]++; map[cp.y + 1][cp.x + 1]++;

            if (size == 2) return;

            map[cp.y][cp.x - 2]++; map[cp.y][cp.x + 2]++;
            map[cp.y - 2][cp.x]++; map[cp.y + 2][cp.x]++;
        }

        private bool IsValid(Point p, int size)
        {
            switch (size)
            {
                case 1:
                    if (p.x < 1 || p.x > 8 || p.y > 7) return false;
                    break;
                case 2:
                    if (p.x > 7 || p.y > 7) return false;
                    break;
                case 3:
                    if (p.x < 2 || p.x > 7 || p.y > 5) return false;
                    break;
            }
            return true;
        }

        private bool CheckMap()
        {
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (map[i][j] != 0) return false;
                }
            }
            return true;
        }

        private bool CheckDraw(Point p, int size)
        {
            Point cp = CenterPos(p, size);

            if (map[cp.y][cp.x] < 0) return false;
            if (map[cp.y][cp.x - 1] < 0 || map[cp.y][cp.x + 1] < 0) return false;
            if (map[cp.y - 1][cp.x] < 0 || map[cp.y + 1][cp.x] < 0) return false;

            if (size == 1) return true;

            if (map[cp.y - 1][cp.x - 1] < 0 || map[cp.y - 1][cp.x + 1] < 0) return false;
            if (map[cp.y + 1][cp.x - 1] < 0 || map[cp.y + 1][cp.x + 1] < 0) return false;

            if (size == 2) return true;

            if (map[cp.y][cp.x - 2] < 0 || map[cp.y][cp.x + 2] < 0) return false;
            if (map[cp.y - 2][cp.x] < 0 || map[cp.y + 2][cp.x] < 0) return false;

            return true;
        }

        private Point CenterPos(Point p, int size)
        {
            Point ret = p;

            switch (size)
            {
                case 1:
                    ret.y++;
                    break;
                case 2:
                    ret.x++; ret.y++;
                    break;
                case 3:
                    ret.y += 2;
                    break;
            }
            return ret;
        }
    }

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

            Blur BL = new Blur(n);

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

                BL.MakeMap(input, i);
            }
            BL.Solve();
        }
    }
}

Measured memory_bytes: 9524