#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  string s1, s2, s3;
  cin >> t;
  map<string, int> mp;
  mp["polycarp"] = 1;
  while (t--) {
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    transform(s3.begin(), s3.end(), s3.begin(), ::tolower);
    mp[s1] = mp[s3] + 1;
  }
  map<string, int>::iterator it;
  int ans = 0;
  for (it = mp.begin(); it != mp.end(); ++it)
    if (it->second > ans) ans = it->second;
  cout << ans << endl;
  return 0;
}
