import java.io.*;
import java.util.*;

public class FamilyTree
{
    static class Entry
    {
	String descendant;
	String spouse;
	List<Entry> children;
    }

    static void print(Entry entry, int level)
    {
	for (int l = 0; l < level; l++)
	{
	    System.out.print("\t");
	}
	System.out.print("*");
	System.out.println(entry.descendant);
	if (entry.spouse != null)
	{
	    for (int l = 0; l < level; l++)
	    {
		System.out.print("\t");
	    }
	    System.out.print(" ");
	    System.out.println(entry.spouse);
	    for (Entry child : entry.children)
	    {
		print(child, level + 1);
	    }
	}
    }

    public static void main(String[] args)
    {
	Scanner in = new Scanner(System.in);
	PrintStream out = System.out;

	int N = in.nextInt();
	while (N != 0)
	{
	    Map<String, Entry> map = new HashMap<String, Entry>();
	    List<Entry> orphans = new ArrayList<Entry>();
	    for (int n = 0; n < N; n++)
	    {
		int CHILDREN = in.nextInt();
		String descendant = in.next();
		String spouse = in.next();
		List<Entry> children = new ArrayList<Entry>();
		for (int c = 0; c < CHILDREN; c++)
		{
		    String child = in.next();
		    Entry entry;
		    if (map.containsKey(child))
		    {
			entry = map.get(child);
		    }
		    else
		    {
			entry = new Entry();
			entry.descendant = child;
			map.put(child, entry);
		    }
		    children.add(entry);
		    orphans.remove(entry);
		}
		Entry entry;
		if (map.containsKey(descendant))
		{
		    entry = map.get(descendant);
		    entry.spouse = spouse;
		    entry.children = children;
		}
		else if (map.containsKey(spouse))
		{
		    entry = map.get(spouse);
		    entry.spouse = descendant;
		    entry.children = children;
		}
		else
		{
		    entry = new Entry();
		    entry.descendant = descendant;
		    entry.spouse = spouse;
		    entry.children = children;
		    map.put(descendant, entry);
		    map.put(spouse, entry);
		    orphans.add(entry);
		}
	    }
	
	    print(orphans.get(0), 0);
	    
	    N = in.nextInt();
	}
    }
}
