#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> m;
  int n, ans = 1;
  string a, b;
  cin >> n;
  m["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> b;
    for (int i = 0; i < a.size(); i++)
      if ('A' <= a[i] && a[i] <= 'Z') a[i] = a[i] - 'A' + 'a';
    for (int i = 0; i < b.size(); i++)
      if ('A' <= b[i] && b[i] <= 'Z') b[i] = b[i] - 'A' + 'a';
    m[a] = m[b] + 1;
    ans = max(ans, m[a]);
  }
  cout << ans << '\n';
  return 0;
}
