#include <bits/stdc++.h>
using namespace std;
map<string, vector<string>> g;
long long dfs(string v, string parent, long long h) {
  long long answer = h;
  for (auto to : g[v]) {
    if (to == parent) continue;
    answer = max(answer, dfs(to, v, h + 1));
  }
  return answer;
}
void solve() {
  long long n;
  cin >> n;
  string s1, s2;
  for (long long i = 0; i < n; i++) {
    cin >> s1 >> s2 >> s2;
    for (size_t j = 0; j < s1.size(); j++) {
      if ('A' <= s1[j] && s1[j] <= 'Z') {
        s1[j] = char(s1[j] - 'A' + 'a');
      }
    }
    for (size_t j = 0; j < s2.size(); j++) {
      if ('A' <= s2[j] && s2[j] <= 'Z') {
        s2[j] = char(s2[j] - 'A' + 'a');
      }
    }
    g[s2].push_back(s1);
    g[s1].push_back(s2);
  }
  cout << dfs("polycarp", "$", 0) + 1;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
