#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > G;
int go(const string& x) {
  int r = 0;
  for (string y : G[x]) r = max(r, go(y));
  return r + 1;
}
int main() {
  int n;
  cin >> n;
  set<string> nodes;
  while (n--) {
    string a, b;
    cin >> a >> b >> b;
    for (char& c : a) c = tolower(c);
    for (char& c : b) c = tolower(c);
    G[b].push_back(a);
  }
  int ans = 0;
  for (auto x : G) ans = max(ans, go(x.first));
  cout << ans << endl;
  return 0;
}
