#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int n, ans;
map<string, vector<string> > g;
map<string, int> dep;
void dfs(string v, string f) {
  if (f != "a") dep[v] = dep[f] + 1;
  if (g[v].size() == 0) ans = max(dep[v], ans);
  for (string u : g[v]) {
    if (u != f) {
      dfs(u, v);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string a, b, c;
    cin >> a >> b >> c;
    for (int j = 0; j < a.length(); j++) {
      if (a[j] >= 65 && a[j] <= 90) a[j] += ('a' - 'A');
    }
    for (int j = 0; j < c.length(); j++) {
      if (c[j] >= 65 && c[j] <= 90) c[j] += ('a' - 'A');
    }
    g[c].push_back(a);
  }
  dfs("polycarp", "a");
  cout << ans + 1 << "\n";
  return 0;
}
