#include <bits/stdc++.h>
using namespace std;
int max_deep = 0;
int deep = 0;
string to_lower(string a) {
  int i;
  for (i = 0; i < a.size(); i++) a[i] = tolower(a[i]);
  return a;
}
std::map<string, int> my_map;
vector<vector<int> > graph;
std::string a, b, c;
void dfs(int x) {
  deep++;
  if (deep > max_deep) max_deep = deep;
  for (int i = 0; i < graph[x].size(); i++) {
    dfs(graph[x][i]);
  }
  deep--;
}
int main() {
  my_map["polycarp"] = 0;
  graph.resize(1);
  graph[0].resize(0);
  int n;
  scanf("%i\n", &n);
  for (int i = 0; i < n; i++) {
    std::cin >> a >> b >> c;
    a = to_lower(a);
    c = to_lower(c);
    if (my_map.find(a) == my_map.end()) {
      my_map[a] = graph.size();
      graph.resize(graph.size() + 1);
    }
    if (my_map.find(c) == my_map.end()) {
      my_map[c] = graph.size();
      graph.resize(graph.size() + 1);
    }
    graph[my_map[c]].push_back(my_map[a]);
  }
  int i, j;
  dfs(0);
  printf("%i", max_deep);
}
