#include <bits/stdc++.h>
using namespace std;
void boost() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
}
int n;
map<string, int> m;
int main() {
  cin >> n;
  m["polycarp"] = 1;
  int mx = 0;
  for (int i = 1; i <= n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] >= 'A' && a[i] <= 'Z') {
        a[i] += 32;
      }
    }
    for (int i = 0; i < c.size(); i++) {
      if (c[i] >= 'A' && c[i] <= 'Z') {
        c[i] += 32;
      }
    }
    if (m[c]) {
      m[a] = m[c] + 1;
      mx = max(mx, m[a]);
    }
  }
  cout << mx;
  return 0;
}
