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 collections import OrderedDict
#from collections import defaultdict
#from functools import reduce
#from itertools import groupby
#sys.setrecursionlimit(10**6)
#from itertools import accumulate
from collections import Counter
import math
import sys
import os
from io import BytesIO, IOBase
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")
'''
from threading import stack_size,Thread
sys.setrecursionlimit(10**6)
stack_size(2**25)
'''
def listt():
    return [int(i) for i in input().split()]
 
def gcd(a,b): 
   return math.gcd(a,b) 
 
def lcm(a,b): 
    return (a*b) // gcd(a,b) 

def factors(n):
    step = 2 if n%2 else 1
    return set(reduce(list.__add__,([i, n//i] for i in range(1, int(math.sqrt(n))+1, step) if n % i == 0)))

def comb(n,k):
    factn=math.factorial(n)
    factk=math.factorial(k)
    fact=math.factorial(n-k)
    ans=factn//(factk*fact)
    return ans

def is_prime(n): 
    if n <= 1: 
        return False
    if n == 2: 
        return True
    if n > 2 and n % 2 == 0: 
        return False

    max_div = math.floor(math.sqrt(n)) 
    for i in range(3, 1 + max_div, 2): 
        if n % i == 0: 
            return False
    return True
def maxpower(n,x):
    B_max = int(math.log(n, x)) + 1 #tells upto what power of x n is less than it like 1024->5^4
    return B_max
def binaryToDecimal(n): 
    return int(n,2) 


#d=sorted(d.items(),key=lambda a:a[1]) sort dic accc to values
#g=pow(2,6)
#a,b,n,m=map(int,input().split())
#print ("{0:.8f}".format(min(l)))
#t=1
def f(y):
    if y in d:
        return d[y]
    if y==1:
        d[y]=1
        return d[y]
    elif y%2==0:
        d[y]= min(f(y//2)+1,abs(y-n))
        return d[y]
    else:
        d[y]= min(f(y+1)+1,f(y-1)+1,abs(y-n))
        return d[y]
''' 
#t=int(input())
for _ in range(1):
    #n=int(input())
    d={}
    n,m=map(int,input().split())
    if n>=m:
        print(m-n)
    else:
        print(f(m))    
'''        
n = int(input())
cnt = {'polycarp': 1}
for i in range(n):
    arr = input().split()
    name1 = arr[0].lower()
    name2 = arr[2].lower()
    cnt[name1] = cnt[name2]+1
print(max(cnt.values()))

    
    
    
    
    
    
    
    
    
    
    
    
    
    
