#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;
using std::make_pair;
using std::map;
using std::pair;
using std::queue;
using std::string;
using std::vector;
int main() {
  map<string, vector<string>> graph;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string name, name2;
    cin >> name;
    cin >> name2;
    cin >> name2;
    auto tolower = [](string& s) -> string {
      std::transform(s.begin(), s.end(), s.begin(), ::tolower);
      return s;
    };
    graph[tolower(name2)].push_back(tolower(name));
  }
  int longest_chain = 0;
  queue<pair<string, int>> bfsq;
  bfsq.push(make_pair("polycarp", 1));
  while (!bfsq.empty()) {
    auto from = bfsq.front();
    bfsq.pop();
    if (from.second > longest_chain) {
      longest_chain = from.second;
    }
    for (auto to : graph[from.first]) {
      bfsq.push(make_pair(to, from.second + 1));
      cerr << "go from " << from.first << " " << from.second << " to " << to
           << std::endl;
    }
  }
  cout << longest_chain << endl;
  return 0;
}
