#include <bits/stdc++.h>
using namespace std;
const int N = 200020;
const int mod = 1000000007;
int main() {
  int n;
  cin >> n;
  map<string, int> v;
  v["polycarp"] = 1;
  while (n--) {
    string a, b, c;
    cin >> a >> b >> c;
    transform(a.begin(), a.end(), a.begin(), ::tolower);
    transform(c.begin(), c.end(), c.begin(), ::tolower);
    v[a] = v[c] + 1;
  }
  int ans = 0;
  map<string, int>::iterator it = v.begin();
  for (; it != v.end(); it++) ans = max(ans, it->second);
  cout << ans << endl;
  return 0;
}
