#include <bits/stdc++.h>
using namespace std;
void Lower(string &s) {
  for (int i = 0; i < (int)s.length(); i++) {
    s[i] = tolower(s[i]);
  }
}
void solve() {
  int n;
  scanf("%d", &n);
  int ans = 1;
  map<string, int> re;
  re["polycarp"] = 1;
  while (n--) {
    string a, b, c;
    cin >> a >> b >> c;
    Lower(a);
    Lower(c);
    int e = re[c] + 1;
    if (e > ans) ans = e;
    re[a] = e;
  }
  printf("%d", ans);
}
int main() {
  solve();
  return 0;
}
