#include <bits/stdc++.h>
using namespace std;
map<string, vector<string>> nbh;
map<string, bool> visited;
int dfs(string v, int d) {
  int r = d;
  if (!visited[v]) {
    visited[v] = true;
    for (auto u : nbh[v]) {
      r = max(r, dfs(u, d + 1));
    }
  }
  return r;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string v, bin, u;
    cin >> v >> bin >> u;
    for (auto &c : v) {
      c = (char)tolower(c);
    }
    for (auto &c : u) {
      c = (char)tolower(c);
    }
    nbh[u].push_back(v);
  }
  int best = -1;
  for (auto i : nbh) {
    visited.clear();
    best = max(best, dfs(i.first, 0) + 1);
  }
  cout << best << "\n";
  return 0;
}
