#include <bits/stdc++.h>
struct cpr {
  char x[26];
  int l;
};
int rpt[300][300];
int comp(cpr* a, char* b) {
  int l = strlen(b);
  if (a->l != l) {
    return 0;
  }
  int rs = strcmp(a->x, b);
  return !rs;
}
cpr x[300];
int num = 0;
int n;
void upcsr(char* x) {
  int l = strlen(x);
  for (int i = 0; i < l; i++) {
    if (x[i] >= 'a' && x[i] <= 'z') {
      x[i] -= 'a' - 'A';
    }
  }
}
char buff[3][30];
char* plc = "POLYCARP";
int maxm = 1;
void dfs(int x, int dpt) {
  if (dpt > maxm) {
    maxm = dpt;
  }
  for (int i = 0; i < num; i++) {
    if (rpt[x][i]) {
      dfs(i, dpt + 1);
    }
  }
}
int main() {
  scanf("%i\n", &n);
  num = 1;
  memcpy(x[0].x, plc, 9);
  x[0].l = 8;
  memset(rpt, 0, sizeof(rpt));
  for (int i = 0; i < n; i++) {
    scanf("%s%s%s\n", buff[0], buff[1], buff[2]);
    upcsr(buff[0]);
    upcsr(buff[2]);
    int id1 = 0;
    for (id1 = 0; id1 < num; id1++) {
      if (comp(&x[id1], buff[0])) {
        break;
      }
    }
    int id2 = 0;
    for (id2 = 0; id2 < num; id2++) {
      if (comp(&x[id2], buff[2])) {
        break;
      }
    }
    if (id1 == num) {
      strcpy(x[num].x, buff[0]);
      x[num].l = strlen(buff[0]);
      num++;
    }
    rpt[id2][id1] = 1;
  }
  dfs(0, 1);
  printf("%i", maxm);
}
