#include <bits/stdc++.h>
using namespace std;
map<string, int> m;
int main() {
#pragma warning(disable : 4996)
  int n, ans = 0;
  scanf("%d", &n);
  m["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    char a[30], b[30];
    scanf("%s reposted %s", a, b);
    for (int j = strlen(a) - 1; j >= 0; j--) a[j] = tolower(a[j]);
    for (int j = strlen(b) - 1; j >= 0; j--) b[j] = tolower(b[j]);
    int l = m[b] + 1;
    m[a] = l;
    ans = max(l, ans);
  }
  printf("%d", ans);
  return 0;
}
