#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int i, j;
  string u, v, t;
  unordered_map<string, int> depth;
  depth["polycarp"] = 1;
  int maxDepth = 1;
  for (i = 0; i < n; i++) {
    cin >> u >> t >> v;
    transform(u.begin(), u.end(), u.begin(), ::tolower);
    transform(v.begin(), v.end(), v.begin(), ::tolower);
    depth[u] = depth[v] + 1;
    maxDepth = max(maxDepth, depth[u]);
  }
  cout << maxDepth << endl;
  return 0;
}
