Rooks

No attempts yetTime limit1sMemory limit128 MB

Problem

On an n×nn \times n chessboard (1n30001 \le n \le 3000) we place nn rooks, one per rook index. The placement must satisfy the following rules.

  • For each i=1,,ni = 1, \dots, n, rook ii must be placed inside a rectangle given by two corners (ai,bi)(a_i, b_i) and (ci,di)(c_i, d_i), where (ai,bi)(a_i, b_i) is the top-left square (row, column) and (ci,di)(c_i, d_i) is the bottom-right square, with 1aicin1 \le a_i \le c_i \le n and 1bidin1 \le b_i \le d_i \le n. The top-left square of the board is (1,1)(1, 1) and the bottom-right square is (n,n)(n, n). In other words, the row of rook ii must lie in [ai,ci][a_i, c_i] and its column must lie in [bi,di][b_i, d_i].
  • No two rooks may attack each other, meaning no two rooks share the same row or the same column.

Decide whether all rooks can be placed inside their rectangles without any two attacking each other, and if so, output one such placement.

Input

The first line contains a single integer nn (1n30001 \le n \le 3000). Each of the next nn lines contains four integers aia_i, bib_i, cic_i, did_i separated by single spaces, describing the rectangle for rook ii (1aicin1 \le a_i \le c_i \le n, 1bidin1 \le b_i \le d_i \le n, every value between 11 and nn).

Output

If no valid placement exists, print the single word NIE (Polish for "no").

Otherwise print nn lines. Line ii contains the row and column of rook ii separated by a single space, where the row lies in [ai,ci][a_i, c_i] and the column lies in [bi,di][b_i, d_i]; the rooks are listed in the same order as their rectangles were given.

Because several placements can be valid, print the lexicographically smallest one. Compare two placements by the sequence formed by reading the values in order: row of rook 11, column of rook 11, row of rook 22, column of rook 22, and so on. Equivalently, make the row of rook 11 as small as possible, then its column as small as possible, then the row of rook 22, then its column, and so on.