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.
# import collections
# from collections import defaultdict
# from re import A, L
# from re import A, I, L, M
import sys
from sys            import setrecursionlimit, stdin, stdout, stderr
# from bisect         import bisect_left, bisect_right
from collections    import defaultdict, deque, Counter
# from itertools      import accumulate, combinations, permutations, product
# from functools      import lru_cache, cmp_to_key, reduce
# from heapq          import heapify, heappush, heappop, heappushpop, heapreplace
# import math
# import copy
import os,io
from io import BytesIO, IOBase
# from tkinter import N
# from unittest import TestResult
# from traceback import print_list

# list(map(int,input().split()))
# s = input().strip()
# n = int(input())
# @lru_cache(maxsize=100000)  

from math import sqrt

 
def isprime(x):
    i = 2
    if x <= 3:
        return 1
    if x % 2 == 0:
        return 0
    i += 1
    while i * i <= x:
        if x % i == 0:
            return 0
        i += 2
    return 1

# from itertools import combinations
 
def countbits(x):
    c = 0
    while x:
        if x & 1: c += 1
        x >>= 1
    return c

##############################################
##############################################
############ Code starts here ################
############################################## 



####  BINARY SEARCH  ###  DP ####  MATH  ##########
 
import copy

    
# n = (2 * (10 ** 5)) + 5
# parent = [i for i in range(n)]
# size = [1 for i in range(n)]
 
 
# def find(root):
#     a = root
#     while parent[a] != a:
#         a = parent[a]
#     while root != a:
#         nextnode = parent[root]
#         parent[root] = a
#         root = nextnode
#     return a
 
 
# def union(a, b):
#     a = find(a)
#     b = find(b)
#     if a != b:
#         if size[a] < size[b]:
#             a, b = b, a
#         parent[b] = a
#         size[a] += size[b]
#         return True
#     return False   

    

 
 
# @bootstrap
    
    
def main():
    # list(map(int,input().split()))
    # s = input().strip()
    # t=int(input())
 # hash={i:2**i for i in range(32)}
    # for _ in range(t):
    # N=int(input())
        
    # from math import gcd
    # t=int(input())
 # hash={i:2**i for i in range(32)}
    import math
    
    # for case in range(int(input())):
        # n, m,k,q = map(int,input().split())
        # n, m, k, q = mp(int)
    dic={}
    j='A'
    arr=[chr(ord(j)+i) for i in range(26)]
    m='a'
    arr1=[chr(ord(m)+i) for i in range(26)]
    
    for i in range(len(arr)):
        dic[arr[i]]=arr1[i]
        dic[arr1[i]]=arr1[i] 
    for i in range(10):
        dic[str(i)]=str(i)
    
    n=int(input())
    hash=defaultdict(list)
    for i in range(n):
        
        s=input().split(' ')
        s1=''
        for i in s[0]:
            
            s1+=dic[i]
        s2=''
        for i in s[2]:
            
            s2+=dic[i]
        hash[s2].append(s1)
        
    deq=deque(['polycarp'])
    step=0
    # print(hash)
    while deq:
        step+=1
        for j in range(len(deq)):
            a=deq.popleft()
            
            for key in hash[a]:
                # print(key)
                deq.append(key)
    print(step)
        
        
                
        
            
                
        
        
                
                
                
                
            
              
    
        
                   
                    
                
                
            
        
                            

                
            
            
            
            
            
            
            
            
            
        
            
                    
            
            
            
                        
                    
                            
                
                
                
                
                    
                
                
                
                            
                    
                
                        
                    
            
                
            
            
            
            
        
                
                
            
               
        
        
        
            
            
            
                        
                    
            
            
                    
                                
            
                    
                
                
            
    
    
     
    
# Fast input
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# input = sys.stdin.readline

if __name__ == "__main__":
    main()
    
# def bootstrap(f, stack=[]):
#     from types import GeneratorType
#     def wrappedfunc(*args, **kwargs):
#         if stack:
#             return f(*args, **kwargs)
#         else:
#             to = f(*args, **kwargs)
#             while True:
#                 if type(to) is GeneratorType:
#                     stack.append(to)
#                     to = next(to)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     to = stack[-1].send(to)
#             return to
 
#     return wrappedfunc
 
 
# @bootstrap