import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Make sure an integer is present
        if (!sc.hasNextInt()) {
            System.out.println("Invalid input");
            return;
        }

        int n = sc.nextInt();

        // According to the prompt, n must be positive and at most 10
        if (n <= 0 || n > 10) {
            System.out.println("Invalid input");
            return;
        }

        Map<String, Integer> freq = new LinkedHashMap<>();

        // Read exactly n words (tokens) — works for space-separated or newline-separated input
        for (int i = 0; i < n; i++) {
            if (!sc.hasNext()) {
                System.out.println("Invalid input");
                return;
            }
            String word = sc.next().trim();

            // Validate word contains only letters
            if (!word.matches("[A-Za-z]+")) {
                System.out.println("Invalid input");
                return;
            }

            freq.put(word, freq.getOrDefault(word, 0) + 1);
        }

        // Print in order of first appearance
        for (Map.Entry<String, Integer> e : freq.entrySet()) {
            System.out.println(e.getKey() + " " + e.getValue());
        }
    }
}
