#include <bits/stdc++.h>
using namespace std;
int main() {
  int maxr = 0;
  int n;
  cin >> n;
  map<string, int> arr;
  arr["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string str1, str2, str3;
    cin >> str1 >> str2 >> str3;
    for (string::iterator it = str1.begin(); it != str1.end(); it++) {
      *it = tolower(*it);
    }
    for (string::iterator it = str3.begin(); it != str3.end(); it++) {
      *it = tolower(*it);
    }
    arr[str1] = arr[str3] + 1;
    if (arr[str1] > maxr) maxr = arr[str1];
  }
  cout << maxr;
  cin.get();
  cin.get();
  return 0;
}
