#include <bits/stdc++.h>
using namespace std;
int G[210][210], ans = 0, cnt = 0, n;
char buf[30] = "Polycarp", id[210][30];
int fun(char *name) {
  for (int i = 0; i < strlen(name); i++) name[i] = tolower(name[i]);
  for (int i = 0; i < cnt; i++) {
    if (strcmp(id[i], name) == 0) return i;
  }
  strcpy(id[cnt], name);
  return cnt++;
}
void dfs(int cur, int dis) {
  ans = max(ans, dis);
  for (int i = 0; i < n + 1; i++) {
    if (G[cur][i]) dfs(i, dis + 1);
  }
}
int main() {
  scanf("%d", &n);
  getchar();
  fun(buf);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%s", buf);
    a = fun(buf);
    scanf("%s %s", buf, buf);
    b = fun(buf);
    G[b][a] = 1;
  }
  dfs(0, 1);
  cout << ans << endl;
  return 0;
}
