#T125. 小明的账单

小明的账单

Description

During a gathering, Xiao Ming accidentally lost his wallet. In the following days, he will face a series of card replacement procedures and a pile of unpaid bills... After Xiao Ming's repeated pleas, his boss finally agreed to postpone the payment deadline for the bills. However, the boss proposed a condition: each day, Xiao Ming must select the two bills with the smallest and largest amounts from all unpaid bills and pay them off. The remaining unpaid bills will be carried over to the next day. Please help him determine the order of payments.

Input Format

  • Line 1: A positive integer ( N ) (( N \leq 15,000 )), representing the total number of days Xiao Ming spends replacing his bank card.
  • Lines 2 to ( N+1 ): Each line describes the bills received on a given day. It starts with a non-negative integer ( M ) (( M \leq 100 )), indicating the number of bills received that day, followed by ( M ) positive integers (each less than ( 1,000,000,000 )), representing the amounts of each bill.
  • The input data guarantees that Xiao Ming can pay two bills each day.

Output Format

Output ( N ) lines, each containing two space-separated integers, representing the amounts of the smallest and largest bills paid on that day, respectively.

4
3 3 6 5
2 8 2
3 7 1 7
0

3 6
2 8
1 7
5 7