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

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

        public Point(int x, int y)
        {
            this.x = x;
            this.y = 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 = new Point(0, 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);

                    DFS(next);

                    RevMap(next, i);
                }
            }
        }

        private Point SearchNext(Point p)
        {
            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) return new Point(j, i);
                    else return new Point(-1, -1);
                }
            }
            return new Point(-1, -1);
        }

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

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

            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 = p;

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

            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;
        }
    }

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