import java.util.Scanner;
class List
{
String from[][] = new String[105][2105];
String to[][] = new String[105][2105];
int len1 = 0, len2 = 0;
int lens1[] = new int[105];
int lens2[] = new int[105];
List(int x)
{
to[0][0] = "zichuan";
to[1][0] = "linzi";
to[2][0] = "zhoucun";
to[3][0] = "boshan";
len2 = 4;
lens2[0] = lens2[1] = lens2[2] = lens2[3] = 1;
}
int fin(String a[][], int len, String x)
{
int i;
for(i = 0; i < len; i++)
{
if(a[i][0].equals(x) == true)break;
}
if(i < len)return i;
else return -1;
}
void SetData(String nam, String fro, String ti)
{
int p;
p = fin(from, len1, fro);
if(p == -1)
{
from[len1][0] = fro;
from[len1][1] = nam;
lens1[len1] = 2;
len1++;
}
else
{
from[p][lens1[p]] = nam;
lens1[p]++;
}
p = fin(to, len2, ti);
if(p != -1)
{
to[p][lens2[p]] = nam;
lens2[p]++;
}
}
void Print()
{
int i, j;
for(i = 0; i < len1; i++)
{
System.out.print(from[i][0] + " :");
for(j = 1; j < lens1[i]; j++)
{
System.out.print(" " + from[i][j]);
}
System.out.println();
}
for(i = 0; i < len2; i++)
{
System.out.print(to[i][0] + " :");
for(j = 1; j < lens2[i]; j++)
{
System.out.print(" " + to[i][j]);
}
System.out.println();
}
}
}
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n, i, j, k;
String nam, fro, to;
List li = new List(1);
n = cin.nextInt();
nam = cin.nextLine();
for(i = 0; i < n; i++)
{
nam = cin.next();
fro = cin.next();
to = cin.next();
li.SetData(nam, fro, to);
}
li.Print();
cin.close();
}
}