#include <bits/stdc++.h>
using namespace std;
map<string, int> l;
int main() {
  int n;
  string x, y, z;
  cin >> n;
  l["polycarp"] = 1;
  int m = 1;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    for (auto& c : x) c = tolower(c);
    for (auto& c : z) c = tolower(c);
    l[x] = l[z] + 1;
    m = max(m, l[x]);
  }
  cout << m << endl;
  return 0;
}
