// Arup Guha
// 10/13/2018
// Program to show the use of Java's HashMap

import java.util.*;

public class TestHashMap {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		HashMap<String,Integer> votes = new HashMap<String,Integer>();
		
		// Read in all of the votes.
		for (int i=0; i<n; i++) {
			
			String name = stdin.next();
			
			// You already have a vote.
			if (votes.containsKey(name)) {
				int curVotes = votes.get(name);
				votes.put(name,  curVotes+1);
			}
			else {
				votes.put(name, 1);
			}
		}
		
		for (String name: votes.keySet())
			System.out.println(name+"\t"+votes.get(name));
		
	}

}
