#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, int> d = map<string, int>{{"polycarp", 1}};
  while (n--) {
    string f, s, t;
    cin >> t >> s >> f;
    transform(t.begin(), t.end(), t.begin(), ::tolower);
    transform(f.begin(), f.end(), f.begin(), ::tolower);
    d[t] = d[f] + 1;
  }
  int ans = 0;
  for (auto x : d) ans = max(ans, x.second);
  cout << ans;
}
