#include <bits/stdc++.h>
using namespace std;
string a = "polycarp";
vector<pair<string, int> > v;
int main() {
  int n;
  cin >> n;
  string s1, re, s2;
  cin >> s1 >> re >> s2;
  for (int i = 0; i < s1.size(); i++)
    if (s1[i] >= 'A' && s1[i] <= 'Z') s1[i] += 32;
  for (int i = 0; i < s2.size(); i++)
    if (s2[i] >= 'A' && s2[i] <= 'Z') s2[i] += 32;
  v.push_back({s1, 2});
  for (int i = 0; i < n - 1; i++) {
    cin >> s1 >> re >> s2;
    for (int i = 0; i < s1.size(); i++)
      if (s1[i] >= 'A' && s1[i] <= 'Z') s1[i] += 32;
    for (int i = 0; i < s2.size(); i++)
      if (s2[i] >= 'A' && s2[i] <= 'Z') s2[i] += 32;
    bool b = 0;
    for (int j = 0; j < v.size(); j++) {
      if (s2 == v[j].first) v.push_back({s1, v[j].second + 1}), b = 1;
    }
    if (!b) v.push_back({s1, 2});
  }
  int maxi = 2;
  for (int i = 0; i < v.size(); i++) maxi = max(maxi, v[i].second);
  cout << maxi;
}
