#include <bits/stdc++.h>
using namespace std;
map<string, int> level;
int ans = 1;
void dfs(string src, map<string, list<string>> adj) {
  for (auto i : adj[src]) {
    level[i] = level[src] + 1;
    ans = max(ans, level[i]);
    dfs(i, adj);
  }
}
int main() {
  int n;
  cin >> n;
  level["polycarp"] = 1;
  map<string, list<string>> adj;
  for (int i = 1; i <= n; i++) {
    string v, x, u;
    cin >> v >> x >> u;
    transform(v.begin(), v.end(), v.begin(), ::tolower);
    transform(u.begin(), u.end(), u.begin(), ::tolower);
    adj[u].push_back(v);
  }
  dfs("polycarp", adj);
  cout << ans << endl;
}
