#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > arr;
int ans = 0, Max = 0;
void DFS(string s, int dem) {
  Max = max(dem, Max);
  for (auto i : arr[s]) {
    DFS(i, ++dem);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  string x, y, z;
  for (int i = 0; i < n; i++) {
    cin >> x >> y >> z;
    for (int j = 0; j < x.size(); j++)
      x[j] = ((x[j] >= 'A' && x[j] <= 'Z') ? x[j] + 32 : x[j]);
    for (int j = 0; j < z.size(); j++)
      z[j] = ((z[j] >= 'A' && z[j] <= 'Z') ? z[j] + 32 : z[j]);
    arr[x].push_back(z);
  }
  for (auto i : arr) {
    Max = 0;
    DFS(i.first, 1);
    ans = max(ans, Max);
  }
  cout << ans;
}
