#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int n, ans = 1;
string s, s1, s2;
string lower_case(string s) {
  int j = 1;
  int len = s.length();
  for (int i = 0; i < len; i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
    if (s[i] == ' ')
      j++;
    else if (j == 1)
      s1 += s[i];
    else if (j == 3)
      s2 += s[i];
  }
  return s;
}
int main() {
  cin >> n;
  getchar();
  mp["polycarp"] = 1;
  while (n--) {
    getline(cin, s);
    s1 = "";
    s2 = "";
    s = lower_case(s);
    mp[s1] = mp[s2] + 1;
    ans = max(ans, mp[s1]);
  }
  cout << ans << endl;
}
