The City’s Favorite Car

A research analyst is studying last year’s car purchases to see which car brands are most popular in different cities. Each purchase record tells which city the car was bought in and which brand it was.

Your task is to build a simple report: for each city, find the most frequently purchased brand.

The first line of the input contains a single integer n - the number of purchase records from last year.

The next n lines each contain two space-separated words: a city and a brand (the words don't contain spaces).

The program should print one line per city: the city name, followed by a space, followed by the most popular brand in that city.

If there is a tie in a city (two or more brands with the same highest count), print the alphabetically smallest brand for that city.

Print the cities in alphabetical order.

Input

Output

8
Springfield Toyota
Shelbyville Ford
Springfield Honda
Ogdenville Ford
Springfield Toyota
Shelbyville Ford
Ogdenville Tesla
Ogdenville Ford

Ogdenville Ford
Shelbyville Ford
Springfield Toyota

6
A Alfa
B Beta
A Beta
B Alfa
C Gamma
C Delta

A Alfa
B Alfa
C Delta

5
Metropolis BMW
Metropolis Audi
Metropolis BMW
Metropolis Audi
Metropolis Audi

Metropolis Audi

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue