#include <bits/stdc++.h>
using namespace std;
vector<long long> arr[202];
long long vis[202];
long long dis[202];
vector<string> names;
long long getNumber(string s) {
  long long k;
  for (long long i = 0; i < names.size(); i++) {
    if (names[i] == s) {
      k = i + 1;
      break;
    }
  }
  return k;
}
void BFS(long long node) {
  vis[node] = 1;
  dis[node] = 0;
  queue<long long> q;
  q.push(node);
  long long curr;
  while (!q.empty()) {
    curr = q.front();
    q.pop();
    for (long long child : arr[curr]) {
      if (vis[child] == 0) {
        q.push(child);
        dis[child] = dis[curr] + 1;
        vis[child] = 1;
      }
    }
  }
}
int main() {
  long long n;
  cin >> n;
  names.push_back("polycarp");
  long long k1, k2 = 1;
  string s, name1, name2;
  long long m = n;
  while (m--) {
    cin >> name1 >> s >> name2;
    for_each(name1.begin(), name1.end(), [](char& c) { c = tolower(c); });
    for_each(name2.begin(), name2.end(), [](char& c) { c = tolower(c); });
    names.push_back(name1);
    k2++;
    k1 = getNumber(name2);
    arr[k1].push_back(k2);
    arr[k2].push_back(k1);
  }
  BFS(1);
  long long max = 0;
  for (long long i = 1; i <= n + 1; i++) {
    if (dis[i] > max) max = dis[i];
  }
  cout << max + 1;
  return 0;
}
