Problem F. Guess the Convex Polygon

There is a convex polygon P on the Cartesian plane satisfying the following conditions:

  1. The number of vertices n satisfies 3<=n<=20, and each vertex (x,y) satisfies |x|,|y|<=10000.
  2. (0,0) is strictly inside P.
  3. No two edges are collinear.
  4. No edges are parallel to x or y axis.
  5. Vertices have integer coordinates.

Your task is to "guess" the polygon.

Interaction Protocol

Your program should read from standard input, and write to standard output. After printing each line to the standard output, you should flush the output, by calling fflush(stdout) or cout << flush in C/C++, flush(output) in Pascal and System.out.flush() in Java. Please read general instructions for interactive problems for more information.

First, read the number of test cases T (1<=T<=100). For each test case, you can issue one or more AskX and AskY commands followed by one Answer command.

CommandDescription
AskX x0Returns c, the number of intersection points between P and line x=x0, and their y coordinates, y1 y2 ... yc.
AskX y0Returns c, the number of intersection points between P and line y=y0, and their x coordinates, x1 x2 ... xc.
Answer n
x1 y1
x2 y2
...
xn yn
Tell us your answer. The vertices must be in counter-clockwise but you can start from any vertex. This command does not return anything.

Each returned coordinate is given in "reduced fraction form" by two integer a and b, that means the coordinate is a/b.

If your program violated any of these rules (bad format, invalid arguments etc), the server will exit immediately, and you will receive Protocol Violation (PV).

Protocol Limit

For each test case, you can issue at most 500 Ask (AskX or AskY) commands, otherwise you'll get Protocol Limit Exceeded (PLE).

Sample Interaction

1
             AskX -6
1 2 1
             AskX -5
2 -5 1 17 5
             AskY 2
2 16 1 -6 1
             AskY -20
0
             Answer 5
             8 -9
             16 2
             -1 9
             -6 2
             -5 -5

Note that this interaction is only valid and does not mean the user program can really deduce the answer from the AskX/AskY commands before it.


Rujia Liu's Present 7: Hello, Interactive Problems!
Problemsetter: Rujia Liu (Idea), Yiming Li (Contest Materials)
Source: Chinese Olympiad in Informatics 2003
Special thanks: Yubin Wang, Md. Mahbubul Hasan