#K3581. Participant Name Announcement

    ID: 25614 Type: Default 1000ms 256MiB

Participant Name Announcement

Participant Name Announcement

You are given multiple test cases. In each test case, there are several participants. Each participant is represented by their first name and the city they come from.

The announcer needs to call out the participants' names following these rules:

  • If a participant's first name appears only once in the test case, print the first name only.
  • If the same first name appears more than once, then for each occurrence:
    • If the first name appears with a single city and only once, print only the first name.
    • Otherwise, print both the first name and the city exactly as given.

More formally, let \(f\) be a function on participants such that for a participant with first name \(a\) and city \(b\):

\[ f(a,b)=\begin{cases} a, & \text{if the total count of } a \text{ is 1}\\ a\ b, & \text{otherwise} \end{cases} \]

Process the participants in the order they appear in the input and output the corresponding callouts line by line.

inputFormat

The input begins with an integer \(T\) (the number of test cases). Each test case is described as follows:

  1. An integer \(N\) (the number of participants).
  2. Followed by \(N\) lines, each containing two strings separated by a space: the first name and the city of the participant.

The input is read from standard input (stdin).

outputFormat

For each test case, output \(N\) lines. Each line should contain either the participant's first name alone (if the first name is unique) or the first name and city (if the first name appears more than once or appears more than once with the same city).

The output is written to standard output (stdout).

## sample
1
3
john newyork
mike losangeles
john boston
john newyork

mike john boston

</p>