#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > g;
unordered_set<string> vis;
int dfs(string node) {
  if (vis.find(node) != vis.end()) {
    return 0;
  }
  int tot = 1;
  vis.insert(node);
  for (auto to : g[node]) {
    tot += dfs(to);
  }
  return tot;
}
int main() {
  int n, maior = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, e, foo;
    cin >> s >> foo >> e;
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    transform(e.begin(), e.end(), e.begin(), ::tolower);
    g[s].emplace_back(e);
  }
  for (auto vertex : g) {
    vis = unordered_set<string>();
    maior = max(maior, dfs(vertex.first));
  }
  cout << maior << '\n';
}
