#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> mp;
int a[500];
int main() {
  scanf("%d", &n);
  string s;
  int c = 0;
  for (int i = 1; i <= n; i++) {
    int id1, id2;
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      if (s[j] < 97) s[j] = s[j] + 32;
    if (mp[s] == 0)
      id1 = ++c, mp[s] = id1;
    else
      id1 = mp[s];
    cin >> s;
    cin >> s;
    for (int j = 0; j < s.size(); j++)
      if (s[j] < 97) s[j] = s[j] + 32;
    if (mp[s] == 0)
      id2 = ++c, mp[s] = id2;
    else
      id2 = mp[s];
    a[id1] = id2;
  }
  int ans = 0;
  for (int i = 1; i <= 2 * n; i++) {
    if (a[i] != 0) {
      c = 0;
      int j = i;
      while (j != 0) {
        j = a[j];
        c++;
      }
      ans = max(ans, c);
    }
  }
  printf("%d\n", ans);
  return 0;
}
