#include <bits/stdc++.h>
using namespace std;
int n, ans, j = 1;
string N1, N2, x;
map<string, vector<string>> A;
void repost(string s) {
  for (int i = 0; i < A[s].size(); i++) j++, repost(A[s][i]);
  ans = max(ans, j), j--;
}
int main() {
  cin >> n;
  while (n--) {
    cin >> N1 >> x >> N2;
    for (int i = 0; i < N1.size(); i++)
      if (N1[i] < 97) N1[i] += 32;
    for (int i = 0; i < N2.size(); i++)
      if (N2[i] < 97) N2[i] += 32;
    A[N2].push_back(N1);
  }
  repost("polycarp");
  cout << ans;
  return 0;
}
