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