#include <bits/stdc++.h>
using namespace std;
string lower(string s) {
  int len = s.length();
  for (int i = 0; i < len; i++) {
    s[i] = tolower(s[i]);
  }
  return s;
}
int main() {
  int n;
  cin >> n;
  set<string> str;
  string nam1, st, nam2;
  map<string, int> _len;
  _len["polycarp"] = 1;
  int res = 0;
  for (int i = 1; i <= n; i++) {
    cin >> nam1 >> st >> nam2;
    string p1 = lower(nam1);
    string p2 = lower(nam2);
    _len[p1] = _len[p2] + 1;
    res = max(res, _len[p1]);
  }
  printf("%d\n", res);
  return 0;
}
