#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  mp["polycarp"] = 1;
  int cnt = 1;
  for (int i = 0; i < n; i++) {
    string s;
    getline(cin >> std::ws, s);
    string s1, s2;
    s1 = s.substr(0, s.find(' '));
    s = s.substr(s.find(' ') + 1, s.size() - 1);
    s = s.substr(s.find(' ') + 1, s.size() - 1);
    s2 = s;
    for (int i = 0; i < s1.size(); i++) {
      s1[i] = tolower(s1[i]);
    }
    for (int i = 0; i < s2.size(); i++) {
      s2[i] = tolower(s2[i]);
    }
    int ans = mp[s2] + 1;
    if (ans > cnt) cnt = ans;
    mp[s1] = ans;
  }
  cout << cnt;
}
