// editor5
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        if(n <= 0) {
            System.out.println("Invalid input");
            return;
        }
        sc.nextLine();
        Map<String, Integer> map = new LinkedHashMap<>();
        
        for(int i = 0; i<n; i++) {
            String words = sc.nextLine().trim();
            if (!word.matches("[a-zA-Z]+")) {
                System.out.println("Invalid input");
                return;
            }
            
            map.put(words, map.getOrDefault(words, 0) + 1);
        }
        
        for(Map.Entry entry : map.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}