Problem: This is an interactive task.

Dasha and NN like playing chess. While playing a match they decided that normal chess isn't interesting enough for them, so they invented a game described below.

There are 666 black rooks and 1 white king on the chess board of size 999 × 999. The white king wins if he gets checked by rook, or, in other words, if he moves onto the square which shares either a row or column with a black rook.

The sides take turns, starting with white. NN plays as a white king and on each of his turns he moves a king to one of the squares that are adjacent to his current position either by side or diagonally, or, formally, if the king was on the square (x, y), it can move to the square (nx, ny) if and only max (|nx - x|, |ny - y|) = 1 , 1 ≤ nx, ny ≤ 999. NN is also forbidden from moving onto the squares occupied with black rooks, however, he can move onto the same row or column as a black rook.

Dasha, however, neglects playing by the chess rules, and instead of moving rooks normally she moves one of her rooks on any space devoid of other chess pieces. It is also possible that the rook would move onto the same square it was before and the position wouldn't change. However, she can't move the rook on the same row or column with the king.

Each player makes 2000 turns, if the white king wasn't checked by a black rook during those turns, black wins. 

NN doesn't like losing, but thinks the task is too difficult for him, so he asks you to write a program that will always win playing for the white king. Note that Dasha can see your king and play depending on its position.

Input

In the beginning your program will receive 667 lines from input. Each line contains two integers x and y (1 ≤ x, y ≤ 999) — the piece's coordinates. The first line contains the coordinates of the king and the next 666 contain the coordinates of the rooks. The first coordinate denotes the number of the row where the piece is located, the second denotes the column. It is guaranteed that initially the king isn't in check and that all pieces occupy different squares.

Output

After getting king checked, you program should terminate immediately without printing anything extra.

Interaction

To make a move with the king, output two integers x and y (1 ≤ x, y ≤ 999) — the square to which the king would be moved. The king cannot move onto the square already occupied by a rook. It is guaranteed that the king would always have a valid move.

After each of your turns read the rook's turn in the following format: a single line containing three integers k, x and y (1 ≤ k ≤ 666, 1 ≤ x_i, y_i ≤ 999) — the number of the rook that would move and the square it would move to. It is guaranteed that the rook wouldn't move to a square already occupied by another chess piece, but it can move onto the square where it was before the turn so that its position wouldn't change. It is guaranteed that the move does not put your king into a check. If your king got in check, all three integers would be equal to -1 and in that case your program should terminate immediately.

After printing your turn do not forget to output end of line and flush the output. Otherwise you will get Idleness limit exceeded. To do this, use:

  * fflush(stdout) or cout.flush() in C++;
  * System.out.flush() in Java;
  * flush(output) in Pascal;
  * stdout.flush() in Python;
  * see documentation for other languages.



Answer "0 0 0" instead of a correct answer means that you made an invalid query. Exit immediately after receiving "0 0 0" and you will see Wrong answer verdict. Otherwise you can get an arbitrary verdict because your solution will continue to read from a closed stream.

Hacks are not allowed for this problem.

Example

Input

999 999
1 1
1 2
2 1
2 2
1 3
2 3
&lt;...&gt;
26 13
26 14
26 15
26 16

1 700 800

2 1 2

&lt;...&gt;

-1 -1 -1


Output












999 998

999 997

&lt;...&gt;

999 26

Note

The example is trimmed. The full initial positions of the rooks in the first test are available at <https://pastebin.com/qQCTXgKP>. It is not guaranteed that they will behave as in the example.

Solution (in JAVA):

Solution:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.FileNotFoundException;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Asgar Javadov
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        FenwickTree.Fenwick2D tree = new FenwickTree.Fenwick2D(1000, 1000);
        IntPair[] rooks;
        int[][] track = new int[1000][1000];

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            Point king = in.readPoint();
            rooks = in.readIntPairArray(666);

            for (IntPair r : rooks) {
                tree.update(r.first, r.second, 1);
            }

            for (int i = 0; i < rooks.length; i++) {
                track[rooks[i].first][rooks[i].second] = i + 1;
            }

            if (!moveKingVertically(king, 500, in, out))
                return;

            if (!moveKingHorizontally(king, 500, in, out))
                return;

            int topLeftSum = tree.get(king.x, king.y);
            if (topLeftSum <= 166) {
                goBottomRight(king, out, in);
                return;
            }

            int topRightSum = tree.get(king.x, 999) - topLeftSum;
            if (topRightSum <= 166) {
                goBottomLeft(king, out, in);
                return;
            }

            int bottomLeftSum = tree.get(999, king.y) - topLeftSum;
            if (bottomLeftSum <= 166) {
                goTopRight(king, out, in);
                return;
            }

            int bottomRightSum = tree.get(999, 999) - topLeftSum - topRightSum - bottomLeftSum;
            if (bottomRightSum <= 166) {
                goTopLeft(king, out, in);
                return;
            }

            throw new RuntimeException("Solution not found!");
        }

        private boolean readAndMoveRook(InputReader in) {
            int k = in.nextInt();
            int kx = in.nextInt();
            int ky = in.nextInt();
            if (k == 0 || k == -1) return false;

            track[rooks[k - 1].first][rooks[k - 1].second] = 0;
            track[kx][ky] = k;

            tree.update(rooks[k - 1].first, rooks[k - 1].second, -1);
            rooks[k - 1].first = kx;
            rooks[k - 1].second = ky;
            tree.update(rooks[k - 1].first, rooks[k - 1].second, 1);
            return true;
        }

        private void goBottomRight(Point king, OutputWriter out, InputReader in) {
            do {
                moveBottomRight(king, out, in);
            } while (readAndMoveRook(in));
        }

        private void moveBottomRight(Point king, OutputWriter out, InputReader in) {
            if (king.x < 999 && king.y < 999) {
                if (track[king.x + 1][king.y + 1] == 0) {
                    king.x++;
                    king.y++;
                } else {
                    king.x++;
                }
            } else if (king.x < 999) {
                king.x++;
            } else {
                king.y++;
            }
            printOut(king, out);
        }

        private void goBottomLeft(Point king, OutputWriter out, InputReader in) {
            do {
                moveBottomLeft(king, out, in);
            } while (readAndMoveRook(in));
        }

        private void moveBottomLeft(Point king, OutputWriter out, InputReader in) {
            if (king.x < 999 && king.y > 1) {
                if (track[king.x + 1][king.y - 1] == 0) {
                    king.x++;
                    king.y--;
                } else {
                    king.x++;
                }
            } else if (king.x < 999) {
                king.x++;
            } else {
                king.y--;
            }
            printOut(king, out);
        }

        private void goTopRight(Point king, OutputWriter out, InputReader in) {
            do {
                moveTopRight(king, out, in);
            } while (readAndMoveRook(in));
        }

        private void moveTopRight(Point king, OutputWriter out, InputReader in) {
            if (king.x > 1 && king.y < 999) {
                if (track[king.x - 1][king.y + 1] == 0) {
                    king.x--;
                    king.y++;
                } else {
                    king.x--;
                }
            } else if (king.x > 1) {
                king.x--;
            } else {
                king.y++;
            }
            printOut(king, out);
        }

        private void goTopLeft(Point king, OutputWriter out, InputReader in) {
            do {
                moveTopLeft(king, out, in);
            } while (readAndMoveRook(in));
        }

        private void moveTopLeft(Point king, OutputWriter out, InputReader in) {
            if (king.x > 1 && king.y > 1) {
                if (track[king.x - 1][king.y - 1] == 0) {
                    king.x--;
                    king.y--;
                } else {
                    king.x--;
                }
            } else if (king.x > 1) {
                king.x--;
            } else {
                king.y--;
            }
            printOut(king, out);
        }

        private void printOut(Point king, OutputWriter out) {
            out.println(king);
            out.flush();
        }

        private boolean moveKingVertically(Point king, int L, InputReader in, OutputWriter out) {
            while (king.x != L) {
                if (king.x < L) {
                    king.x++;
                } else {
                    king.x--;
                }

                out.println(king);
                out.flush();

                if (!readAndMoveRook(in))
                    return false;
            }
            return true;
        }

        private boolean moveKingHorizontally(Point king, int L, InputReader in, OutputWriter out) {
            while (king.y != L) {
                if (king.y < L) {
                    king.y++;
                } else {
                    king.y--;
                }

                out.println(king);
                out.flush();

                if (!readAndMoveRook(in))
                    return false;
            }
            return true;
        }

    }

    static class FenwickTree {
        public static class Fenwick2D {
            int[][] bit;

            public Fenwick2D(int n, int m) {
                this.bit = new int[n][m];
            }

            public void update(int x, int y, int val) {
                for (int i = x; i < bit.length; i |= i + 1)
                    for (int j = y; j < bit[i].length; j |= j + 1)
                        bit[i][j] += val;
            }

            public int get(int x, int y) {
                int ret = 0;
                for (int i = x; i >= 0; i = (i & (i + 1)) - 1)
                    for (int j = y; j >= 0; j = (j & (j + 1)) - 1)
                        ret += bit[i][j];
                return ret;
            }

        }

    }

    static class Point implements Comparable<Point> {
        public int x;
        public int y;

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


        public boolean equals(Object that) {
            Point other = (Point) that;
            return this.x == other.x && this.y == other.y;
        }


        public int compareTo(Point o) {
            if (x != o.x) return Integer.compare(x, o.x);
            return Integer.compare(y, o.y);
        }


        public String toString() {
            return "" + x + " " + y;
        }


        public int hashCode() {
            return 31 * x + y;
        }

        public Point clone() {
            return new Point(this.x, this.y);
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(outputStream);
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

        public OutputWriter(String filename) throws FileNotFoundException {
            super(filename);
        }

        public void close() {
            super.close();
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(readLine());
                } catch (IOException e) {
                    throw new RuntimeException();
                }
            }
            return tokenizer.nextToken();
        }

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

        public Point readPoint() {
            return new Point(nextInt(), nextInt());
        }

        public IntPair[] readIntPairArray(int count) {
            IntPair[] result = new IntPair[count];
            for (int i = 0; i < count; ++i)
                result[i] = IntPair.newPair(nextInt(), nextInt());

            return result;
        }

    }

    static class IntPair implements Comparable<IntPair> {
        public int first;
        public int second;

        public IntPair(int first, int second) {
            this.first = first;
            this.second = second;
        }


        public int compareTo(IntPair o) {
            if (first != o.first)
                return Integer.compare(first, o.first);
            return Integer.compare(second, o.second);
        }

        public static IntPair newPair(int first, int second) {
            return new IntPair(first, second);
        }


        public String toString() {
            return first + " " + second;
        }


        public boolean equals(Object o) {
            if (this == o) return true;
            if (!(o instanceof IntPair)) return false;
            IntPair intPair = (IntPair) o;
            return first == intPair.first &&
                    second == intPair.second;
        }


        public int hashCode() {
            return (31 * first + second);
        }

    }
}