#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500;
const int MOD = 1e9 + 7;
int n, cnt;
int ar[MAX_N], h[MAX_N];
bool seen[MAX_N];
vector<int> adj[MAX_N];
string name[MAX_N];
string re;
void Init() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> name[cnt] >> re >> name[cnt + 1];
    cnt += 2;
  }
  return;
}
void ToLower() {
  for (int i = 0; i < cnt; i++) {
    for (int j = 0; j < name[i].length(); j++) name[i][j] = tolower(name[i][j]);
  }
  return;
}
void DFS(int now) {
  seen[now] = 1;
  for (auto it : adj[now]) {
    if (!seen[it]) {
      h[it] = h[now] + 1;
      DFS(it);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  Init();
  ToLower();
  int jon = 1;
  string check = "polycarp";
  for (int i = 0; i < cnt; i++) {
    if (name[i] == check) ar[i] = jon;
  }
  for (int i = 0; i < cnt; i++) {
    if (ar[i] == 0) {
      jon++;
      ar[i] = jon;
    }
    for (int j = i + 1; j < cnt; j++) {
      if (name[j] == name[i]) {
        ar[j] = ar[i];
      }
    }
  }
  for (int i = 0; i < cnt - 1; i++) {
    if ((i + 1) % 2 == 1) {
      adj[--ar[i + 1]].push_back(--ar[i]);
    }
  }
  DFS(0);
  sort(h, h + n + 1);
  cout << h[n] + 1 << endl;
}
