History course
You are to give a series of lectures on important historical events, one event per lecture, in some order. Each event lasted for some time interval [a_i, b_i]. We say that two events are related if their intervals have a common point. It would be convenient to schedule lectures on related events close to each other. Moreover, lectures on unrelated events should be given in the order in which the events have taken place (if an event A preceded an unrelated event B, then the lecture on A should precede the lecture on B).
Find the minimum integer k ≥ 0 and an order of the lectures such that any two related events are scheduled at most k lectures apart from each other (lectures number i and j are considered to be |i−j| lectures apart).
Input
The first line of input contains the number of test cases t. The descriptions of the test cases follow:
The first line of each test case contains the number n (1 ≤ n ≤ 50000). Each of the next n lines contains two integers a_i and b_i (-10^9 ≤ a_i ≤ b_i ≤ 10^9) - the ends of the i-th interval. The intervals are pairwise different.
Output
Print the answers to the test cases in the order in which they appear in the input. The first line of the answer to each test case should contain the minimum value of k. The next n lines should list the intervals (in the same format as in the input) in an order such that any two related events are scheduled at most k lectures apart. Remember to put any unrelated intervals in the proper order!