using System.Collections.Generic;
public Rep(string name, string repost)
public static void Main()
int n = Int32.Parse(Console.ReadLine());
Rep[] repData = new Rep[n];
for (int i = 0; i < n; i++)
string rowData = Console.ReadLine();
string[] rowDataSplit = rowData.Split(' ');
repData[i] = new Rep(rowDataSplit[0].ToLower(), rowDataSplit[2].ToLower());
List<List<string>> resList = new List<List<string>>();
resList.Add(new List<string>(){"polycarp"});
for (int i = 0; i < n; i++)
string repDest = repData[i].repost;
for (int j = 0; j < resList.Count; j++)
if (resList[j].Last() == repDest)
resList[searchIndex].Add(repData[i].name);
resList.Add(new List<string>(){repData[i].name});
int maxCount = resList.Max(x => x.Count);
Console.WriteLine(maxCount + 1);