#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int i, j, k, n, m, z, y, x, l, r, curr = 0, x1 = 0, x2 = 0, ans1,
                                              ans = 0;
  cin >> n;
  vector<vector<long long int> > a(n * 2 + 1, vector<long long int>());
  string ch, ch1, waste;
  map<string, long long int> m1;
  x = 1;
  for (i = 0; i < n; i++) {
    cin >> ch >> waste >> ch1;
    transform(ch.begin(), ch.end(), ch.begin(), ::tolower);
    transform(ch1.begin(), ch1.end(), ch1.begin(), ::tolower);
    if (m1[ch1] == 0) {
      m1[ch1] = x;
      x++;
    }
    if (m1[ch] == 0) {
      m1[ch] = x;
      x++;
    }
    a[m1[ch1]].push_back(m1[ch]);
  }
  y = m1["polycarp"];
  queue<pair<long long int, long long int> > q;
  q.push({y, 0});
  while (!q.empty()) {
    y = q.front().first;
    x = q.front().second;
    q.pop();
    for (i = 0; i < a[y].size(); i++) {
      q.push({a[y][i], x + 1});
      if ((x + 1) > ans) {
        ans = x + 1;
      }
    }
  }
  cout << ans + 1;
}
