#include <bits/stdc++.h>
using namespace std;
int getID(char nms[202][30], char s[30], int &len) {
  for (int i = 0; i < 30; ++i) {
    if (s[i] >= 'a' && s[i] <= 'z') s[i] += 'A' - 'a';
  }
  for (int i = 0; i < len; ++i) {
    if (strcmp(nms[i], s) == 0) return i;
  }
  strcpy(nms[len], s);
  len++;
  return len - 1;
}
int search(int mailFrom[202], int mailTo[202], int p, int n, int h) {
  int max = 0;
  for (int i = 0; i < n; ++i) {
    if (mailFrom[i] == p) {
      int ans = search(mailFrom, mailTo, mailTo[i], n, h + 1);
      if (max < ans) max = ans;
    }
  }
  if (max == 0) return h;
  return max;
}
int main() {
  int n;
  while (cin >> n) {
    char nms[202][30] = {0};
    int len = 0;
    int mailFrom[202] = {0};
    int mailTo[202] = {0};
    bool notHead[202] = {0};
    for (int i = 0; i < n; ++i) {
      char n1[30], n2[30], t[30];
      cin >> n1;
      cin >> t;
      cin >> n2;
      mailFrom[i] = getID(nms, n2, len);
      mailTo[i] = getID(nms, n1, len);
      notHead[mailTo[i]] = 1;
    }
    int max = 0;
    for (int i = 0; i < n; ++i) {
      if (!notHead[i]) {
        int ans = search(mailFrom, mailTo, i, n, 1);
        if (ans > max) max = ans;
      }
    }
    cout << max << endl;
  }
  return 0;
}
