#include <bits/stdc++.h>
using namespace std;
vector<int> v[201];
int n, mx;
int cnt;
map<string, int> mp;
bool vis[201];
void dfs(int s, int temp) {
  if (vis[s]) return;
  mx = max(mx, temp + 1);
  vis[s] = true;
  for (auto i : v[s]) dfs(i, temp + 1);
}
int main() {
  cin >> n;
  string start = "polycarp";
  int id = 0;
  mp[start] = id;
  for (int i = 0; i < n; i++) {
    string from, to, temp;
    cin >> to >> temp >> from;
    for (int i = 0; i < to.size(); i++) to[i] = tolower(to[i]);
    for (int i = 0; i < from.size(); i++) from[i] = tolower(from[i]);
    if (mp.find(from) == mp.end()) mp[from] = ++id;
    if (mp.find(to) == mp.end()) mp[to] = ++id, v[mp[from]].push_back(mp[to]);
  }
  int len = v[0].size();
  for (int i = 0; i < len; i++) {
    dfs(v[0][i], 1);
  }
  cout << mx;
  return 0;
}
