import java.util.*;

public class WordFrequencyCounter {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        // Read number of words
        if (!sc.hasNextInt()) {
            System.out.println("Invalid input");
            return;
        }

        int n = sc.nextInt();
        sc.nextLine(); // consume newline

        // Validate n
        if (n <= 0 || n > 10) {
            System.out.println("Invalid input");
            return;
        }

        Map<String, Integer> wordCount = new LinkedHashMap<>();
        boolean invalidWordFound = false;

        for (int i = 0; i < n; i++) {
            if (!sc.hasNextLine()) {
                invalidWordFound = true;
                break;
            }

            String word = sc.nextLine().trim();

            // If word is invalid (empty or contains non-alphabets)
            if (word.isEmpty() || !word.matches("[a-zA-Z]+")) {
                invalidWordFound = true;
                break;
            }

            // ✅ Do NOT lowercase, keep case-sensitive
            wordCount.put(word, wordCount.getOrDefault(word, 0) + 1);
        }

        // If any invalid word found → reject entire input
        if (invalidWordFound) {
            System.out.println("Invalid input");
            return;
        }

        // If catalog is empty → print -1
        if (wordCount.isEmpty()) {
            System.out.println("-1");
            return;
        }

        // Print results in insertion order
        for (Map.Entry<String, Integer> entry : wordCount.entrySet()) {
            System.out.println(entry.getKey() + " " + entry.getValue());
        }
    }
}
