#include <bits/stdc++.h>
using namespace std;
long long ans = -1e9;
map<string, int> mymap;
int main() {
  set<string> s;
  int n;
  cin >> n;
  string s1, s2, s3;
  mymap["polycarp"] = 1;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> s1 >> s2 >> s3;
    std::transform(s3.begin(), s3.end(), s3.begin(), ::tolower);
    std::transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    mymap[s1] = mymap[s3] + 1;
    ans = max(ans, 1ll * mymap[s1]);
  }
  cout << ans << endl;
}
