using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
int x;
x=Int32.Parse(Console.ReadLine());
Dictionary<string, int> dict = new Dictionary<string, int>();
List<string> erdos = new List<string>();
List<string> wszystko = new List<string>();
Dictionary<string, List<string>> biblio = new Dictionary<string, List<string>>();
for (int i = 0; i < x; i++)
{
string line = Console.ReadLine();
string surname, article;
surname = line.Split(' ')[0];
article = line.Split(' ')[1].Replace('"', new char());
if (biblio.ContainsKey(surname))
{
biblio[surname].Add(article);
}
else
biblio.Add(surname, new List<string>() {article});
}
foreach (var item in biblio)
{
dict.Add(item.Key, -1);
}
if (dict.Keys.Contains("P.Erdos")) dict["P.Erdos"] = 0;
int n = 0;
while(dict.Values.Contains(n))
{
foreach (var it in biblio)
{
if (dict[it.Key] == n)
{
foreach (var item in biblio[it.Key])
{
foreach (var surname in biblio.Keys)
{
if (biblio[surname].Contains(item) && !surname.Equals("P.Erdos") && dict[surname] < 0)
{
dict[surname] = n + 1;
}
}
}
}
}
n++;
}
//foreach (var item in biblio["P.Erdos"])
//{
// foreach (var surname in biblio.Keys)
// {
// if (biblio[surname].Contains(item) && !surname.Equals("P.Erdos"))
// {
// dict[surname] = 1;
// }
// }
//}
//foreach (var item in dict)
//{
// Console.WriteLine(item.Key + " " + item.Value);
//}
var list = dict.Keys.ToList();
list.Sort();
foreach (var item in list)
{
if(dict[item]==-1)
Console.WriteLine(item + ": " + "inf");
else
Console.WriteLine(item+": "+ dict[item]);
}
}
}
}