#include <bits/stdc++.h>
using namespace std;
vector<vector<pair<int, int>>> g;
vector<long long> mp, c;
vector<long long> used;
bool kun(long long v) {
  if (used[v]) return 0;
  used[v] = 1;
  for (auto i : g[v]) {
    if (mp[i.second] == -1 || kun(mp[i.second])) {
      mp[i.second] = v;
      c[i.second] = i.first;
      return 1;
    }
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  map<string, int> a;
  int kek = 1;
  a["polycarp"] = 0;
  vector<vector<int>> g(201);
  for (int i = 0; i < n; i++) {
    string s, q, s1;
    cin >> s >> q >> s1;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] <= 'Z' && s[i] >= 'A') {
        s[i] -= ('A' - 'a');
      }
    }
    for (int i = 0; i < s1.size(); i++) {
      if (s1[i] <= 'Z' && s1[i] >= 'A') {
        s1[i] -= ('A' - 'a');
      }
    }
    if (a.find(s) == a.end()) {
      a[s] = kek;
      kek++;
    }
    g[a[s1]].push_back(a[s]);
  }
  queue<int> q;
  q.push(0);
  vector<int> d(201, 1e9);
  d[0] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < g[v].size(); i++) {
      if (d[g[v][i]] > d[v] + 1) {
        d[g[v][i]] = d[v] + 1;
        q.push(g[v][i]);
      }
    }
  }
  int ans = -1e9;
  for (int i = 0; i <= 200; i++) {
    if (d[i] != 1e9) ans = max(ans, d[i]);
  }
  cout << ans + 1;
  return 0;
}
