import java.util.*;
import java.io.*;

// Program to QUICKLY count unique problems solved by using Maps

public class probCountWithMaps{
	public static void main(String[] Args){
		Scanner stdin = new Scanner(System.in);
		
		// Read in the number of problems 
		// (use the nextline to grab the next line token and prevent a false pair)
		int numProblems = Integer.parseInt(stdin.nextLine().trim());
		
		// Initialize the map of sets 
		HashMap<String, HashSet<String>> probMap = new HashMap<String, HashSet<String>>();
		// HashSet<String> users = new HashSet<String>();
		// HashSet<String> userProbPair = new HashSet<String>();
		
		// Read in the user problems pairs
		for (int i = 0; i < numProblems; i++){
			
			// Read in the current pair
			String curProbPerson = stdin.nextLine();
			
			// Break the line up by the space character
			String[] tokenizedLine = curProbPerson.split(" ");
			
			// Get the user from the split line
			String curUser = tokenizedLine[0];
			
			// Check if the user does not exist
			if (!probMap.containsKey(curUser)){
				
				// Add the user to the map
				probMap.put(curUser, new HashSet<String>());
			}
			
			// Add the to the user the problem pair
			probMap.get(curUser).add(curProbPerson);
		}
		
		// Loop through each user and print their number of problems solved
		for (String curUser : probMap.keySet())
		{
			System.out.println(curUser + " " + probMap.get(curUser).size());
		}
	}
}