#C5027. Task Sorting Challenge

    ID: 48631 Type: Default 1000ms 256MiB

Task Sorting Challenge

Task Sorting Challenge

You are given a list of tasks, each represented by a due date and a priority. Your task is to sort the tasks in ascending order based on the due date. For tasks with the same due date, sort them in descending order of priority.

The sorting criteria can be formally defined as follows:

Given a task represented by a tuple \((d, p)\) where \(d\) is the due date and \(p\) is the priority, the tasks should be sorted by the key \((d, -p)\), i.e.,

[ \text{Sort key} = (\text{due date}, -\text{priority}) ]

You will be provided with multiple test cases. For each test case, first an integer \(n\) indicates the number of tasks, followed by \(n\) lines each containing two integers representing the due date and the priority. Your solution should output the sorted tasks for each test case sequentially, with each task on a new line.

inputFormat

The first line of input contains an integer \(T\) denoting the number of test cases. Each test case starts with an integer \(n\), the number of tasks. This is followed by \(n\) lines, each containing two space-separated integers \(d\) and \(p\) representing the due date and priority of a task respectively.

T
n
d1 p1
...
dn pn

outputFormat

For each test case, output the sorted tasks. Each task should be output on a separate line in the format "due_date priority". The tasks of different test cases should follow one after the other without any blank line separation.

## sample
2
3
3 10
1 5
1 8
4
4 2
3 4
2 6
2 8
1 8

1 5 3 10 2 8 2 6 3 4 4 2

</p>