This page is still under construction.

Parts of this page are still being built. What you see may change.

Earthquake Emendations

Time limit1sMemory limit128 MB

Summary
Match each scattered polygon piece to its rotated location in the shattered window schematic.
Level

Medium6 of 10

Topics
Geometry, Hash map, Implementation
Solved
No attempts yet

Problem

A major earthquake has shattered a beautiful stained glass window in a college chapel, leaving colored glass pieces scattered across the floor. The window broke only along its lead joints, so every colored piece is completely intact. Each fallen piece lies either in its original orientation or rotated by a multiple of 90 degrees (π/2\pi/2 radians); no piece has been flipped over (mirrored).

Luckily, a schematic of the original window as it stood before the earthquake was found. From it you know that no two colored pieces of the window have the same shape and size. Using this schematic, write a program that identifies where each scattered piece belongs so the window can be reassembled.

Input

The input consists of several windows to reassemble, given one after another.

Each window begins with a line containing an integer nn (1≤n≤201 \le n \le 20), the number of glass pieces in the window. The next nn lines each describe one distinct colored glass piece as a simple polygon with nonzero area. A polygon with kk vertices (3≤k≤1003 \le k \le 100) is written as its vertices in counter-clockwise order, repeating the first vertex at the end to close it:

x1 y1 x2 y2 … xk yk x1 y1x_1\ y_1\ x_2\ y_2\ \dots\ x_k\ y_k\ x_1\ y_1

Within one polygon all vertices are distinct (that is, (xi,yi)≠(xj,yj)(x_i, y_i) \ne (x_j, y_j) whenever i≠ji \ne j), and no three consecutive vertices are collinear. All coordinates are integers with 0≤xi,yi≤1000 \le x_i, y_i \le 100.

After the nn piece descriptions comes one more line: the schematic of the original window, written as nn non-overlapping polygons concatenated together in the same format. Each schematic polygon is exactly one of the glass pieces above, rotated by a multiple of 90 degrees and then translated.

Windows may be separated by blank lines. A line containing a single 00 marks the end of the input.

Output

For each window, output a single line. For the ii-th glass piece listed in the input (in the given order), print the position at which that piece appears in the schematic. Positions are numbered from 11, in the order the polygons occur in the schematic. Separate the nn numbers with single spaces.

Because no two pieces have the same shape and size, each piece matches exactly one schematic polygon, so this assignment is unique.

Examples3

  1. Example 1

    Input
    2
    1 3 4 3 1 5 1 3
    4 4 4 7 2 7 4 4
    0 0 2 0 2 3 0 0 2 0 4 0 2 3 2 0
    
    4
    0 0 4 0 4 2 2 2 0 0
    0 0 4 0 2 2 0 2 0 0
    4 4 0 4 2 3 4 4
    0 4 4 4 2 6 0 4
    0 0 4 0 2 2 0 0 0 0 2 2 2 4 0 4 0 0 2 2 4 0 4 4 2 4 2 2 0 4 4 4 2 5 0 4
    
    0
    
    Expected output
    1 2
    3 2 4 1
    
  2. Example 2

    Input
    1
    0 0 3 0 0 4 0 0
    0 60 3 60 0 64 0 60
    
    0
    
    Expected output
    1
    
  3. Example 3

    Input
    3
    0 0 4 0 2 2 0 0
    18 0 21 0 21 3 18 3 18 0
    36 0 41 0 36 1 36 0
    0 60 4 60 2 62 0 60 21 60 21 63 18 63 18 60 21 60 41 61 36 61 41 60 41 61
    
    0
    
    Expected output
    1 2 3