Absurdistan Roads III

No attempts yetTime limit2sMemory limit256 MB

Problem

The people of Absurdistan learned how to build roads only last year. Since then, every city has built exactly one road, joining that city to some other city. Every new road can be travelled in both directions.

The tourist guide you bought contains a map with all of the new roads. The map shows the roads only, not which city built which road. You are interested in history, so you want to recover that correspondence.

Given the description of nn roads, assign the roads to the nn cities so that each city built exactly one road. At least one such assignment exists.

Input

The first line contains an integer nn, the number of cities and also the number of roads. (2n1000002 \le n \le 100000)

Each of the next nn lines contains two integers aa and bb, meaning that a road joins city aa and city bb. (1a,bn1 \le a, b \le n, aba \ne b)

Several roads may join the same pair of cities.

Output

Print nn lines. The ii-th line contains two integers ii and bb, meaning that city ii built the road whose other endpoint is city bb. Every road of the input must appear exactly once in the output.

If several assignments are possible, print the one whose sequence b1,b2,,bnb_1, b_2, \dots, b_n is lexicographically smallest.