#include <bits/stdc++.h>
using namespace std;
int findMaxLevel(vector<vector<int>> graph, int index, int level) {
  if (graph[index].size() == 0) return level + 1;
  int maxLevel = 0;
  for (int i = 0; i < graph[index].size(); i++)
    maxLevel = max(findMaxLevel(graph, graph[index][i], level + 1), maxLevel);
  return maxLevel;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<string, int> m;
  vector<vector<int>> graph;
  string a, b, c;
  int j = 1;
  vector<int> v;
  graph.push_back(v);
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    transform(a.begin(), a.end(), a.begin(), ::toupper);
    transform(c.begin(), c.end(), c.begin(), ::toupper);
    if (!m[c]) {
      m[c] = j;
      j++;
      graph.push_back(v);
    }
    if (!m[a]) {
      m[a] = j, j++;
      graph.push_back(v);
    }
    graph[m[c]].push_back(m[a]);
  }
  cout << findMaxLevel(graph, 1, 0);
}
