#K51587. Task Priority Sorting
Task Priority Sorting
Task Priority Sorting
You are given several test cases. In each test case, you are given a number of tasks, each with a name and a priority value. Your goal is to sort the tasks for each test case based on the following criteria:
- Primary: Increasing order of priority (i.e. tasks with lower priority numbers come first).
- Secondary: If two tasks have the same priority, sort them lexicographically (alphabetically) by task name, ignoring case.
The sorted tasks from all test cases should be printed sequentially, with each task on a new line.
Note: When comparing task names, the comparison is case-insensitive. In other words, the sorting order for names is determined by converting them to lowercase.
For a mathematical perspective, if each task is represented as a pair \((name, p)\), then tasks are sorted by the tuple \((p, \text{lower}(name))\) in lexicographical order.
inputFormat
The first line of input contains an integer \(T\) representing the number of test cases.
For each test case:
- The first line contains an integer \(n\), the number of tasks.
- The next \(n\) lines each contain a task description. Each description consists of a task name (a string that may contain alphabets) and an integer priority, separated by a space.
Input is read from stdin.
outputFormat
Output the sorted tasks (from all test cases) to stdout, one task per line. Each line should contain the task name and its priority, separated by a space.
## sample2
4
DesignDB 2
CreateAPI 1
launchApp 3
designUI 2
3
TestApp 1
deploy 2
FixBugs 1
CreateAPI 1
DesignDB 2
designUI 2
launchApp 3
FixBugs 1
TestApp 1
deploy 2
</p>