#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[205];
bool vis[205];
long long dp[205];
void dfs(long long v) {
  vis[v] = true;
  for (long long first : adj[v]) {
    if (!vis[first]) {
      dfs(first);
      dp[v] = max(dp[first] + 1, dp[v]);
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  map<string, long long> m;
  long long curr = 2;
  m["polycarp"] = 1;
  for (long long i = 0; i < n; i++) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    for (char &c : s1) c = tolower(c);
    for (char &c : s3) c = tolower(c);
    if (!m[s1]) m[s1] = curr++;
    if (!m[s3]) m[s3] = curr++;
    adj[m[s3]].emplace_back(m[s1]);
  }
  dfs(1);
  cout << dp[1] + 1;
}
