import java.util.*;
import java.io.*;

// Implements the unique problem counter using Sets

public class probCount{
	public static void main(String[] Args){
		Scanner stdin = new Scanner(System.in);
		
		// Read in the number of user problem pairs
		int numProblems = Integer.parseInt(stdin.nextLine().trim());
		
		// Make sets that stores both the user names and the problem pairs
		HashSet<String> users = new HashSet<String>();
		HashSet<String> userProbPair = new HashSet<String>();
		
		// Read in each user problem pairs
		for (int i = 0; i < numProblems; i++){
			
			// Read in and store the current user problem pair
			String curProbPerson = stdin.nextLine();
			userProbPair.add(curProbPerson);
			
			// Break the line up by the space character
			String[] tokenizedLine = curProbPerson.split(" ");
			
			// Get the user from the split line
			String curUser = tokenizedLine[0];
			
			// Add the user in case they don't already exist
			users.add(curUser);
		}
		
		// Loop through all users
		for (String curUser : users) {
			
			// Initialize a problem counter
			int counter = 0;
			
			// Read in each user problem pair and check 
			for (String pair : userProbPair) {
				
				// Prevent users incorrectly getting problems from longer user names
				if (pair.startsWith(curUser + " "))
				{
					counter++;
				}
			}
			
			// Print the current usern and the number of submissions
			System.out.println(curUser + " " + counter);
		}
	}
}