// Arup Guha
// 3/25/2206
// Example of how to store an undirected graph.
// Input Format discussed in lecture notes...
/*** n -> number of connections
     n lines, with pairs of strings, the people connected.
***/

import java.util.*;

public class GraphStorage {

	public static void main(String[] args) {
	
		// Read number of connections.
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		
		// Where we'll store our graph.
		ArrayList<ArrayList<Integer>> graph = new ArrayList<ArrayList<Integer>>();
		
		// Used to store integer ids for each unique person.
		int id = 0;
		HashMap<String,Integer> idLookUp = new HashMap<String,Integer>();
		
		// Index i will store name i.
		ArrayList<String> nameList = new ArrayList<String>();
		
		// Read through the pairs.
		for (int i=0; i<n; i++) {
			
			// Get the two names.
			String name1 = stdin.next();
			String name2 = stdin.next();
			
			// Add to map if necessary.
			if (!idLookUp.containsKey(name1)) {
				nameList.add(name1);
				idLookUp.put(name1, id++);
				graph.add(new ArrayList<Integer>());
			}
			
			// Do same for name two.
			if (!idLookUp.containsKey(name2)) {
				nameList.add(name2);
				idLookUp.put(name2, id++);
				graph.add(new ArrayList<Integer>());
			}
			
			// Get the ids for both people.
			int u = idLookUp.get(name1);
			int v = idLookUp.get(name2);
			
			// Add v to u's list and u to v's list.
			graph.get(u).add(v);
			graph.get(v).add(u);
		}
		
		// Print names in order.
		System.out.println("Name list in order.");
		for (int i=0; i<nameList.size(); i++)
			System.out.print(nameList.get(i)+" ");
		System.out.println("\n");
		
		// Print map.
		System.out.println("Map contents");
		for (String person: idLookUp.keySet())
			System.out.println(person+" "+idLookUp.get(person));
		System.out.println();

		// Print graph.
		for (int i=0; i<graph.size(); i++) {
			System.out.print("vertex "+i+": ");
			for (Integer x: graph.get(i))
				System.out.print(x+", ");
			System.out.println();
		}
	}
}