import java.util.Arrays;
import java.util.Scanner;

public class valhalla_ak {

    public static char[][][] FIGURES = {
            {
                    "###".toCharArray()
            },
            {
                    "##".toCharArray()
            },
            {
                    "#.".toCharArray(),
                    "##".toCharArray()
            }
    };

    static char[][] deepClone(char[][] a) {
        char[][] res = new char[a.length][];
        for (int i = 0; i < res.length; i++) {
            res[i] = a[i].clone();
        }
        return res;
    }

    static class Field {
        final char[][] f;

        Field(int x, int y) {
            f = new char[y][x];
            for (char[] fx : f) {
                Arrays.fill(fx, '.');
            }
        }

        Field(char[][] f) {
            this.f = f;
        }

        Field update(char[][] figure, int pos) {
            int h = f.length - 1;
            char[][] f = deepClone(this.f);
            outer: for (; h >= figure.length - 1; h--) {
                for (int i = 0; i < figure.length; i++) {
                    for (int j = 0; j < figure[i].length; j++) {
                        if (figure[i][j] == '#' && f[h - i][pos + j] == '#') {
                            break outer;
                        }
                    }
                }
            }
            h++;
            for (int i = 0; i < figure.length; i++) {
                for (int j = 0; j < figure[i].length; j++) {
                    if (figure[i][j] == '#') {
                        f[h - i][pos + j] = '#';
                    }
                }
            }

            for (int i = 0; i < f.length; i++) {
                boolean all = true;
                for (int j = 0; j < f[i].length; j++) {
                    all &= f[i][j] == '#';
                }
                if (all) {
                    for (int k = i + 1; k < f.length; k++) {
                        f[k - 1] = f[k].clone();
                    }
                    i--;
                }
            }
            return new Field(f);
        }

        int score() {
            int res = 0;
            for (char[] fx : f) {
                for (char x : fx) {
                    res += x == '#' ? 1 : 0;
                }
            }
            return res;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            for (int i = f.length - 1; i >= 0; i--) {
                sb.append(new String(f[i])).append("\n");
            }
            return sb.toString();
        }
    }

    static char[][] rotate(char[][] fig) {
        int n = fig.length;
        int m = fig[0].length;
        char[][] res = new char[m][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                res[j][n - 1 - i] = fig[i][j];
            }
        }
        return res;
    }

    static Object turn(Field f, char[][] fig) {
        Field bestField = f.update(fig, 0);
        int bestScore = bestField.score();
        int bestTurn = 0;
        int bestPos = 0;
        for (int turn = 0; turn < 4; turn++) {
            for (int pos = 0; pos < f.f[0].length - fig[0].length + 1; pos++) {
                Field to = f.update(fig, pos);
                if (to.score() < bestScore) {
                    bestField = to;
                    bestScore = to.score();
                    bestTurn = turn;
                    bestPos = pos;
                }
            }
            fig = rotate(fig);
        }
        for (int i = 0; i < f.f.length; i++) {
            for (int j = 0; j < f.f[i].length; j++) {
                f.f[i][j] = bestField.f[i][j];
            }
        }
        return bestTurn + " " + (bestPos + 1);
    }

    public static void main(String[] args) {
        char[][] field = new char[3][5];
        for (char[] fx : field) {
            Arrays.fill(fx, '.');
        }
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Field f = new Field(3, 7);
        for (int i = 0; i < n; i++) {
            int t = in.nextInt() - 1;
            System.out.println(turn(f, FIGURES[t]));
//            System.err.println(f);
            System.out.flush();
        }
    }
}
