#include <bits/stdc++.h>
using namespace std;
int n, x, ma = -1;
vector<vector<string> > na;
vector<string> v;
int dfs(int node) {
  int d = 0;
  for (int i = 0; i < na[node].size(); i++) {
    auto it = find(v.begin(), v.end(), na[node][i]);
    int a = it - v.begin();
    d += 1 + dfs(a);
  }
  return d;
}
int main() {
  cin >> n;
  na = vector<vector<string> >(10000);
  for (int j = 0; j < n; j++) {
    string s, c, z;
    cin >> s >> c >> z;
    for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
    for (int i = 0; i < z.size(); i++) z[i] = tolower(z[i]);
    auto it = find(v.begin(), v.end(), s);
    if (it == v.end()) {
      x = v.size();
      v.push_back(s);
      na[x].push_back(z);
    } else {
      x = it - v.begin();
      na[x].push_back(z);
    }
  }
  for (int i = 0; i < v.size(); i++) {
    ma = max(ma, dfs(i));
  }
  cout << ma + 1;
  return 0;
}
