Under construction

Still being built. Things may change

Duplicate Files

Interview

Time limit2sMemory limit512 MB

Summary
Given file names and unique IDs, keep the smallest ID for each distinct name and print the surviving IDs in increasing order.
Level

Easy3 of 10

Topics
Hash map, Sorting, Array
Solved
No attempts yet

Problem

Many of us have this problem on our computer: we make several copies of the exact same files, which uses more memory. So you finally decided to write a program to remove all duplicate files.

Here is how your computer works. Whenever you create a new file, it gets a unique ID. When you make a copy of an existing file, the new copy gets a new ID. The IDs are relative to time, so older files get smaller IDs, but the IDs are not necessarily sequential. Each file also has a name, and multiple files can have the same name. When two or more files get the same name, they are all exactly the same and are just identical copies of the one of them with the smallest ID.

You are given the list of all files with their names and IDs. Your task is to delete all duplicates and keep only the oldest copy of each file.

Input

Your program will be tested on one or more test cases. The first line of the input contains a single integer T (1 ≤ T ≤ 100), the number of test cases, followed by T test cases.

Each test case starts with a line containing an integer N (1 ≤ N ≤ 105), the number of files, followed by N lines. Each line contains the file name, a space, and the file ID. The file name is a non-empty string of at most 10 lower case English letters, and the ID is a positive integer at most 105.

All IDs are distinct within each test case.

Output

For each test case, print a single line containing the IDs of the files that will not get deleted. The IDs must be sorted in increasing order and separated by a single space.

Examples1

  1. Example 1

    Input
    2
    2
    aaa 6
    aa 5
    3
    file 3
    file 2
    file 1
    
    Expected output
    5 6
    1