#K74067. Most Popular Genre

    ID: 34115 Type: Default 1000ms 256MiB

Most Popular Genre

You are given N users. Each user has a playlist consisting of a list of song genres. Your task is to determine the most popular genre for each user. The most popular genre is defined as the genre that appears most frequently in that user's playlist. In case of a tie, choose the lexicographically smallest genre.

More formally, suppose a user's playlist contains genres with frequencies \( c_1, c_2, \ldots, c_k \) for genres \( g_1, g_2, \ldots, g_k \) respectively, and let \( M = \max\{ c_i \} \). Then, the answer for that user is given by:

[ \min{ g_i \mid c_i = M } ]

Print the most popular genre for each user on a separate line.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer (N) (the number of users).
  • For each user, there are two lines:
    • The first line contains an integer (T) representing the number of songs in the user's playlist.
    • The second line contains (T) space-separated strings, each representing a genre.

outputFormat

For each user, output the most popular genre on a new line to stdout.## sample

1
4
rock rock rock rock
rock

</p>