#include <bits/stdc++.h>
using namespace std;
int n;
map<string, int> connected;
string lower(string s) {
  for (int i = 0; i < s.length(); i++) {
    if (s[i] >= 65 && s[i] <= 90) {
      s[i] += 32;
    }
  }
  return s;
}
int main() {
  connected["polycarp"] = 1;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, x, b;
    cin >> a >> x >> b;
    a = lower(a), b = lower(b);
    connected[a] = connected[b] + 1;
  }
  int cmp = 0;
  for (auto x : connected) {
    cmp = max(x.second, cmp);
  }
  cout << cmp << "\n";
}
