#include <bits/stdc++.h>
using namespace std;
char s[1000][1000], s1[1000][1000];
int i, j, n, maxi = 0;
map<string, int> m;
int main() {
  scanf("%d", &n);
  m.insert(pair<string, int>("polycarp", 1));
  for (i = 0; i < n; i++) {
    scanf("%s", &s[i]);
    scanf("%s", &s1[i]);
    scanf("%s", &s1[i]);
    for (j = 0; s[i][j]; j++) {
      if (s[i][j] >= 'A' && s[i][j] <= 'Z') {
        s[i][j] = s[i][j] + 32;
      }
    }
    for (j = 0; s1[i][j]; j++) {
      if (s1[i][j] >= 'A' && s1[i][j] <= 'Z') {
        s1[i][j] = s1[i][j] + 32;
      }
    }
    int x = m[s1[i]] + 1;
    m.insert(pair<string, int>(s[i], x));
    if (x > maxi) maxi = x;
  }
  printf("%d\n", maxi);
  return 0;
}
