#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> m;
int num = 1;
struct edge {
  int u, v, nex;
} e[3000];
int dd = 0;
int head[3000];
void addedge(int u, int v) {
  e[dd] = (edge){u, v, head[u]};
  head[u] = dd++;
}
int sum[3000];
bool vis[3000];
void bfs(int u) {
  queue<int> q;
  q.push(u);
  vis[u] = 1;
  sum[u] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i != -1; i = e[i].nex) {
      int v = e[i].v;
      if (!vis[v]) {
        q.push(v);
        sum[v] = max(sum[v], sum[u]) + 1;
        vis[v] = 1;
      }
    }
  }
}
int main() {
  cin >> n;
  memset(head, -1, sizeof(head));
  m["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string k, s, d;
    cin >> k >> s;
    cin >> d;
    transform(k.begin(), k.end(), k.begin(), ::tolower);
    transform(d.begin(), d.end(), d.begin(), ::tolower);
    if (m[k] == 0) {
      m[k] = ++num;
    }
    if (m[d] == 0) {
      m[d] == ++num;
    }
    addedge(m[d], m[k]);
  }
  bfs(1);
  int ans = 0;
  for (int i = 1; i <= num; i++) {
    ans = max(ans, sum[i]);
  }
  cout << ans;
  return 0;
}
