#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  long long int n;
  cin >> n;
  map<string, long long int> l;
  long long int length = 1;
  l["Polycarp"] = 1;
  while (n--) {
    string a, b, c;
    cin >> a >> b >> c;
    for (long long int i = 0; i < a.length(); i++) {
      a[i] = tolower(a[i]);
    }
    for (long long int i = 0; i < c.length(); i++) {
      c[i] = tolower(c[i]);
    }
    long long int e = l[c] + 1;
    if (e > length) length = e;
    l[a] = e;
  }
  cout << length + 1 << endl;
}
