#include <bits/stdc++.h>
using namespace std;
map<string, vector<string>> mf;
int ftree(string s) {
  vector<string> v = mf[s];
  if (v.size() == 0) return 1;
  int x = 0;
  for (int i = 0; i < v.size(); i++) {
    x = max(x, ftree(v[i]));
  }
  return x + 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, x, y;
  vector<string> v;
  string s1, s2, s3;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s3 >> s2;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    transform(s2.begin(), s2.end(), s2.begin(), ::tolower);
    mf[s1].push_back(s2);
    v.push_back(s1);
  }
  x = 0;
  for (int i = 0; i < n; i++) {
    x = max(x, ftree(v[i]));
  }
  cout << x << endl;
}
