#include <bits/stdc++.h>
const long long INF = 1e18;
using namespace std;
const long long modulo = 1000000007;
void solve() {
  int n, ans = 1;
  cin >> n;
  map<string, int> mapita;
  mapita["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string a, aux, c;
    cin >> a >> aux >> c;
    transform((a).begin(), (a).end(), a.begin(), ::tolower);
    transform((c).begin(), (c).end(), c.begin(), ::tolower);
    int e = mapita[c] + 1;
    ans = max(ans, e);
    mapita[a] = e;
  }
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  solve();
}
