#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> dp;
  dp.insert(pair<string, int>("polycarp", 1));
  int n;
  cin >> n;
  char nameTo[50];
  char comand[50];
  char nameFrom[50];
  string name1, name2;
  for (int i = 0; i < n; ++i) {
    name1 = "";
    name2 = "";
    cin >> nameTo;
    cin >> comand;
    cin >> nameFrom;
    for (int j = 0; j < strlen(nameTo); ++j) {
      name1 += tolower(nameTo[j]);
    }
    for (int j = 0; j < strlen(nameFrom); ++j) {
      name2 += tolower(nameFrom[j]);
    }
    dp.insert(pair<string, int>(name1, dp[name2] + 1));
  }
  int ans = 0;
  for (auto it = dp.begin(); it != dp.end(); ++it) {
    ans = max((*it).second, ans);
  }
  cout << ans;
  return 0;
}
