1. 

/**
* FWP, Ausgewählte Probleme aus dem ACM Programming Contest, SS10
* Problem: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=16&page=show_problem&problem=1361
* Link: 10420 - List of Conquests
*
* @author Evgeni Pavlidis
* @version 1.0, 06/02/2010
*
* Method : Ad hoc
* Status : Accepted
* Runtime: 0.144
*/

import java.io.*;
import java.util.*;

class Main {

public static void main(String...args) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

int lines = Integer.parseInt(reader.readLine());
Map<String, Set<String>> map = new HashMap<String, Set<String>>();

int offset;
String input;
String city, name;

for(int l = 0; l < lines; l++)
{
input = reader.readLine();
offset = input.indexOf(' ');
city = input.substring(0, offset);

if(!map.containsKey(city))
map.put(city, new HashSet<String>());

map.get(city).add(input.substring(offset+1));
}

//System.out.println(map);

for(String c: new TreeSet<String>(map.keySet()))
System.out.println(c + " " + map.get(c).size());
}
}