#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, i, ma = 0;
  map<string, int> m;
  string s, n1, n2;
  cin >> n;
  while (n--) {
    cin >> n1 >> s >> n2;
    transform(n1.begin(), n1.end(), n1.begin(), ::tolower);
    transform(n2.begin(), n2.end(), n2.begin(), ::tolower);
    m[n1] = m[n2] + 1;
    ma = max(m[n1], ma);
  }
  cout << ma + 1;
}
