#include <bits/stdc++.h>
using namespace std;
map<string, int> A;
string s1, s2, s3;
int n, i, maxdeep;
int main() {
  cin >> n;
  A["polycarp"] = 1;
  while (n--) {
    cin >> s1 >> s2 >> s3;
    for (i = 0; i < s1.size(); i++)
      if (s1[i] >= 'a') s1[i] -= 'a' - 'A';
    for (i = 0; i < s3.size(); i++)
      if (s3[i] >= 'a') s3[i] -= 'a' - 'A';
    A[s1] = A[s3] + 1;
    if (maxdeep < A[s1]) maxdeep = A[s1];
  }
  cout << maxdeep + 1;
  return 0;
}
