#include <bits/stdc++.h>
using namespace std;
int bfs(string src, map<string, list<string> > &m, map<string, int> &visited,
        map<string, int> &level, int &ans) {
  queue<string> q;
  q.push(src);
  visited[src] = 1;
  level[src] = 1;
  ans = 1;
  while (!q.empty()) {
    string curr = q.front();
    q.pop();
    for (auto child : m[curr]) {
      if (!visited[child]) {
        q.push(child);
        level[child] = level[curr] + 1;
        ans = max(ans, level[child]);
        visited[child] = 1;
      }
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<string, int> visited;
  map<string, int> level;
  map<string, list<string> > m;
  for (int i = 1; i <= n; i++) {
    string s1, u, s2;
    cin >> s1 >> u >> s2;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
    m[s2].push_back(s1);
    visited[s1] = 0;
  }
  int ans = INT_MIN;
  cout << bfs("polycarp", m, visited, level, ans);
  return 0;
}
