#K80567. Sort Pokémon Records

    ID: 35559 Type: Default 1000ms 256MiB

Sort Pokémon Records

Sort Pokémon Records

You are given a collection of Pokémon records for multiple test cases. Each record consists of a Pokémon's name and its associated region number. The task is to sort the records in each test case primarily by the region number in ascending order and, for records with the same region number, by the Pokémon's name in alphabetical order.

More formally, for each test case, let each record be represented as a tuple \( (name, region) \). You should sort these tuples according to the following criteria:

  • First, by the region number \( region \) in increasing order.
  • If two records have the same region number, then sort them by the Pokémon's name \( name \) in lexicographical order.

After sorting the records in each test case, output them one per line in the format: name region. Separate consecutive test case outputs with an empty line.

inputFormat

The input is read from standard input and is formatted as follows:

  1. An integer \( T \) on the first line representing the number of test cases.
  2. For each test case:
    • An integer \( N \) on a new line representing the number of Pokémon records.
    • Followed by \( N \) lines, each containing a Pokémon's name (a string) and its region number (an integer), separated by a space.

outputFormat

For each test case, output the sorted Pokémon records, one per line, in the format name region. Insert an empty line between outputs of consecutive test cases.

## sample
1
3
Charmander 2
Bulbasaur 1
Pikachu 2
Bulbasaur 1

Charmander 2 Pikachu 2

</p>