One day Polycarp published a funny picture in a social network making a poll about the color of his handle. Many of his friends started reposting Polycarp's joke to their news feed. Some of them reposted the reposts and so on.

These events are given as a sequence of strings "name1 reposted name2", where name1 is the name of the person who reposted the joke, and name2 is the name of the person from whose news feed the joke was reposted. It is guaranteed that for each string "name1 reposted name2" user "name1" didn't have the joke in his feed yet, and "name2" already had it in his feed by the moment of repost. Polycarp was registered as "Polycarp" and initially the joke was only in his feed.

Polycarp measures the popularity of the joke as the length of the largest repost chain. Print the popularity of Polycarp's joke.
The first line of the input contains integer *n* (1 ≤ *n* ≤ 200) — the number of reposts. Next follow the reposts in the order they were made. Each of them is written on a single line and looks as "name1 reposted name2". All the names in the input consist of lowercase or uppercase English letters and/or digits and have lengths from 2 to 24 characters, inclusive.

We know that the user names are case-insensitive, that is, two names that only differ in the letter case correspond to the same social network user.
# from queue import PriorityQueue
# import math 
# import math 
# from functools import reduce
# def find_gcd(list):
#     x = reduce(gcd, list)
#     return x
# from itertools import combinations



# import qrcode 
# text = qrcode.make("momen ashraf")
# text.save("qr.png")



# def f(i,l,s,index_list,ans):
    
#     if s % 2 == 0 and s :
#         ans.append(index_list)
#         return True
#     elif i == len(l):
#         return True
    
#     else :
#         op = f(i+1,l,s+l[i],index_list+[i+1],ans)
#         if op :
#             pass 
#         else :
#             f(i+1,l,s,index_list,ans)
        
#      __IMPORTANT__ 
#      Make tree and get depth
# import math
# def f(original_l,l,ll,d):
#     if l == []:
#         return 
#     else :
#         i = original_l.index(max(l))
#         ll[i] = d 
#         j = l.index(max(l))
#         f(original_l,l[:j],ll,d+1)
#         f(original_l,l[j+1:],ll,d+1)      

def f(i,n,k,l,ll,c,lll):
    if c <= n and c not in lll:
        ll.append(1)
        lll.append(c)
    if i == len(l) :
        return
    f(i+1,n,k,l,ll,c+l[i],lll)
    f(i+1,n,k,l,ll,c,lll)


# l = list(map(int,"2	35 7 11	13	17	19	23 29	31	37	41	43	47	53	59	61	67 71	73	79	83	89	97	101	103	107	109 113	127	131	137	139	149	151	157	163	167 173	179	181	191	193	197	199	211	223	227 229	233	239	241	251	257	263	269	271	277 281	283	293	307	311	313	317	331	337	347 349	353	359	367	373	379	383	389	397	401 409	419	421	431	433	439	443	449	457	461 463	467	479	487	491	499	503	509	521	523 541	547	557	563	569	571	577	587	593	599 601	607	613	617	619	631	641	643	647	653 659	661	673	677	683	691	701	709	719	727 733	739	743	751	757	761	769	773	787	797 809	811	821	823	827	829	839	853	857	859 863	877	881	883	887	907	911	919	929	937 941	947	953	967	971	977	983	991	997".split())) 
# l.sort()

# def max_substring0(s):
#     return max(s.split('1'), key=len) 
# def max_substring1(s):
#     return max(s.split('0'), key=len)

def merge(l,r):
    i = j = 0 
    merged = []
    while i < len(l) and j < len(r):
        if l[i] <= r[j] :
            merged.append(l[i])
            i+=1
        else :
            merged.append(r[j])
            j+=1 
    merged+=l[i:]
    merged+=r[j:]
    return merged 

def merger_sort(l):
    if len(l)<=1 :
        return l 
    m = len(l)//2 
    left = merger_sort(l[:m])
    right = merger_sort(l[m:])
    merged = merge(left,right)
    return merged 

def dfs(graph,start):
    vis = {}
    level = {}
    for i in graph.keys():
        vis[i] = 0
        level[i] = 0
    stack = [start] 
    vis[start] = 1 
    level[start] = 1 
    while stack :
        parent = stack.pop(-1)
        vis[parent] = 1
        for i in graph[parent]:
            child = i
            if not vis[child]:
                stack.append(child)
                vis[child] = 1 
                level[child] = level[parent]+1
    return max(level.values())
graph = {}
n = int(input())
l = []
names = []
for i in range(n):
    x = input().split()
    l.append([x[0].lower(),x[2].lower()])
    names.append(x[0].lower())
    names.append(x[2].lower())
names = set(names)
for i in names :
    graph[i] = []

for i in l :
    graph[i[1]].append(i[0])
print(dfs(graph,"polycarp"))
