#include <bits/stdc++.h>
using namespace std;
bool compareLengths(pair<string, int> p, pair<string, int> q) {
  return p.second < q.second;
}
int main() {
  int n;
  map<string, int> lengths;
  cin >> n;
  lengths["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string reposter, lol, poster;
    cin >> reposter >> lol >> poster;
    std::transform(reposter.begin(), reposter.end(), reposter.begin(),
                   ::tolower);
    std::transform(poster.begin(), poster.end(), poster.begin(), ::tolower);
    lengths[reposter] = lengths[poster] + 1;
  }
  auto max = max_element(lengths.begin(), lengths.end(), compareLengths);
  cout << max->second << endl;
  return 0;
}
