Placing elements in databases according to a numeric key not only simplifies searching for a specific element, but also enables more efficient use of the CPU cache: any contiguous memory segment stores elements with close key values. This is particularly useful, for example, when accessing all elements whose keys lie within a given range.
The situation becomes more complicated if the keys represent points on a two-dimensional grid, as is the case, for instance, in GPS navigation systems. If the points are sorted first by and then by , then elements located close to each other in memory will have identical values but may differ significantly in . At the same time, points with equal values may be located far apart on the plane. To better preserve spatial locality, the data can be ordered along a continuous space-filling curve.

Consider one such curve, known as the Hilbert curve. It starts at the point and ends at , visiting all points of the square with corners at and (S, S). The curve is defined recursively as follows: divide the square into four equal parts with a common point at (S/2, S/2), and recursively fill each part with a scaled and appropriately rotated copy of the full Hilbert curve.
First, the lower-left square is filled with a curve going from to (0, S/2). Then the upper-left square is filled from (0, S/2) to (S/2, S/2). Next, the upper-right square is filled from (S/2, S/2) to (S, S/2). Finally, the lower-right square is filled from (S, S/2) to .
On the other hand, the Hilbert curve can also be viewed as the limit of a sequence of polygonal lines, the first few of which are shown in the figure.
You are given a set of points that must be sorted according to their order of traversal along the Hilbert curve. Although the curve intersects itself infinitely many times (for example, at the point (S/2, S/2)), the condition that is odd guarantees that every integer point is visited exactly once.
The first line contains two integers and S~(1 \le n \le 200000, 1 \le S < 10^9, S is odd. Each of the next lines describes a point: line i+1 contains two integers x_i and y_i~(0 \le x_i, y_i \le S) and a name — a string of at most characters consisting of letters and digits (–, –, –). No two points share the same coordinates or the same name.
Print lines — the names of the points, each on a separate line, sorted according to their order along the Hilbert curve.
Example 1