Binary Scale

No attempts yetTime limit1sMemory limit128 MB

Problem

A binary scale is a special device that can measure any value in the open interval (0,1)(0, 1) with a fixed precision. The precision is set with a dial that can be turned to 1,2,3,,101, 2, 3, \dots, 10. When the precision is set to mm, the scale measures in units of 1/2m1 / 2^m.

A measurement is recorded as a pair (,m)(\ell, m). Such a pair means the precision is set to mm and the scale reads \ell, so the weight of the measured object is /2m\ell / 2^m. Here \ell is a positive integer, and since the scale only reads values in (0,1)(0, 1) we have 0<<2m0 < \ell < 2^m.

Write a program that orders the measurements from the smallest value to the largest. Each measurement is given as a pair (,m)(\ell, m). Different pairs that represent the same value (for example (1,2)(1, 2) and (2,3)(2, 3), both equal to 1/41/4) must be ordered by increasing reading \ell, the first element of the pair.

Input

The program reads from standard input. The first line contains an integer nn (1n200001 \le n \le 20\,000), the number of pairs. Each of the next nn lines contains one pair i\ell_i and mim_i, separated by a single space. For every pair, 1mi101 \le m_i \le 10 and 1i<2mi1 \le \ell_i < 2^{m_i}.

Output

The program writes to standard output. Output the nn input pairs, reordered so that pairs with smaller measured values come before pairs with larger measured values. Pairs with equal measured values are printed in non-decreasing order of their reading \ell. Print each pair in the same format as the input, that is, the two integers i\ell_i and mim_i separated by a single space.