// Arup Guha
// 3/25/2026
// Solution to Kattis Problem: Unbearable Zoo
// https://open.kattis.com/problems/zoo

import java.util.*;

public class zoo {

	public static void main(String[] args) {
	
		// Have to read line by line, get # of animals in the first case.
		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine());
		int loop = 1;
		
		// Go to end of input.
		while (n != 0) {
		
			// Will store # of each type of animal here.
			HashMap<String,Integer> map = new HashMap<String,Integer>();
			
			// Read through each animal.
			for (int i=0; i<n; i++) {
			
				// Skip over all but the last token.
				StringTokenizer tok = new StringTokenizer(stdin.nextLine());
				while (tok.countTokens() > 1) tok.nextToken();
				
				// Finally get the animal name in lower case.
				String animal = tok.nextToken().toLowerCase();
				
				// Add 1 to current entry.
				if (map.containsKey(animal))
					map.put(animal, map.get(animal)+1);
				
				// First time, set entry to 1.
				else
					map.put(animal, 1);
			}
			
			// Copy keys to an ArrayList...
			ArrayList<String> keys = new ArrayList<String>();
			for (String s: map.keySet())
				keys.add(s);
			
			// Sort it.
			Collections.sort(keys);
			
			// Output.
			System.out.println("List "+loop+":");
			for (String s: keys)
				System.out.println(s+" | "+map.get(s));
		
			// Get next case.
			n = Integer.parseInt(stdin.nextLine());
			loop++;
		}
	}
}
