#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, ans = 1, x = 0;
  string a, b, s;
  map<string, int> f;
  f["Polycarp"] = 1;
  cin >> n;
  while (n--) {
    cin >> a >> b >> s;
    for (int i = 0; i < a.size(); i++) a[i] = tolower(a[i]);
    for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
    x = f[s] + 1;
    if (x > ans) ans = x;
    f[a] = x;
  }
  cout << ans + 1;
  return 0;
}
