#include <bits/stdc++.h>
using namespace std;
void to_low(string& str) {
  for (int i = 0; i < str.length(); i++) str[i] = tolower(str[i]);
}
int main() {
  ios::sync_with_stdio(false);
  map<string, int> leaves;
  leaves["polycarp"] = 1;
  int n, max_num = 1;
  string to, from;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> to >> from >> from;
    to_low(to);
    to_low(from);
    leaves[to] = leaves[from] + 1;
    if (leaves[to] > max_num) max_num = leaves[to];
  }
  cout << max_num;
  return 0;
}
