#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int dp[100005];
int vis[100005];
int dfs(long long node) {
  vis[node] = 1;
  int ans = 1;
  for (auto i : adj[node])
    if (!vis[i])
      ans = max(dfs(i) + 1, ans);
    else
      ans = max(ans, 1 + dp[i]);
  return dp[node] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    int n, i, j, k;
    cin >> n;
    int ct = 1;
    map<string, int> a;
    for (j = 0; j < n; j++) {
      string s1, s2, s3;
      cin >> s1 >> s2 >> s3;
      for (i = 0; i < (long long int)s1.size(); i++) s1[i] = tolower(s1[i]);
      for (i = 0; i < (long long int)s3.size(); i++) s3[i] = tolower(s3[i]);
      if (!a[s1]) a[s1] = ct++;
      if (!a[s3]) a[s3] = ct++;
      adj[a[s3]].push_back(a[s1]);
    }
    for (i = 1; i < ct; i++) {
      if (!vis[i]) {
        int ans = dfs(i);
      }
    }
    int ans = 0;
    for (i = 1; i < ct; i++) ans = max(ans, dp[i]);
    cout << ans;
  }
  return 0;
}
