import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        if(!sc.hasNextInt()){ 
            System.out.print("Invalid input"); 
            return; 
        }
        int n = sc.nextInt();
        sc.nextLine(); 

        if(n <= 0){
            System.out.print("Invalid input");
            return;
        }

        ArrayList<String> arr = new ArrayList<>();
        for(int i = 0; i < n; i++){
            if(!sc.hasNextLine()){ 
                System.out.print("Invalid input");
                return;
            }
            arr.add(sc.nextLine().trim()); // 🔹 handles spaces
        }

        Map<String, Integer> map = new LinkedHashMap<>(); 
        for(String s : arr){
            map.put(s, map.getOrDefault(s, 0) + 1);
        }

        int count = 0;
        for(Map.Entry<String, Integer> entry : map.entrySet()){
            count++;
            System.out.print(entry.getKey() + " " + entry.getValue());
            if(count < map.size()) System.out.println(); // 🔹 avoids extra newline
        }
    }
}
