// Arup Guha
// 11/17/2019
// Solution to 2014 Va Tech HS Contest Problem: Un-bear-able Zoo

import java.util.*;

public class zoo {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int n = Integer.parseInt(stdin.nextLine());
		int loop = 1;
		
		// Process each case.
		while (n != 0) {
		
			// Store map of animals to frequency here.
			TreeMap<String,Integer> map = new TreeMap<String,Integer>();
		
			// Go through each animal. 
			for (int i=0; i<n; i++) {
			
				// Parse out the last token...
				StringTokenizer tok = new StringTokenizer(stdin.nextLine());
				String name = tok.nextToken();
				while (tok.hasMoreTokens())
					name = tok.nextToken();
				name = name.toLowerCase();
					
				// Add 1 since we've seen this before.
				if (map.containsKey(name))
					map.put(name, map.get(name)+1);
					
				// Place 1 for this animal.
				else
					map.put(name, 1);
			}
			
			// Header
			System.out.println("List "+loop+":");
			
			// Just remove these in order and print.
			while (map.size() > 0) {
				String name = map.firstKey();
				System.out.println(name+" | "+map.get(name));
				map.remove(name);
			}
			
			// Go to next case.
			n = Integer.parseInt(stdin.nextLine());
			loop++;
		}
			
	}
}