#include <bits/stdc++.h>
using namespace std;
map<string, string> p;
vector<string> user;
int ans = 1, tmp, n;
string s1, s2, tam;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s1 >> tam >> s2;
    for (int j = 0; j < s1.length(); j++) {
      if (s1[j] >= 'A' && s1[j] < 'a') s1[j] += 32;
    }
    for (int j = 0; j < s2.length(); j++) {
      if (s2[j] >= 'A' && s2[j] < 'a') s2[j] += 32;
    }
    if (i == 1) user.push_back(s2);
    user.push_back(s1);
    p[s1] = s2;
  }
  for (int i = 0; i < user.size(); i++) {
    string t = user[i];
    int tmp = 1;
    while (p[t] != "") {
      tmp++;
      t = p[t];
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}
