#include <bits/stdc++.h>
using namespace std;
vector<int> v[200];
int ans = 0;
void dfs(int node, int d) {
  if (d > ans) ans = d;
  for (auto x : v[node]) dfs(x, d + 1);
}
int main() {
  int n, cnt = 0;
  string s1, s2, s3;
  cin >> n;
  map<string, int> m;
  m["polycarp"] = ++cnt;
  while (n--) {
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    transform(s3.begin(), s3.end(), s3.begin(), ::tolower);
    m[s1] = ++cnt;
    v[m[s3]].push_back(m[s1]);
  }
  dfs(1, 1);
  cout << ans << '\n';
  return 0;
}
