#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
void amin(T& a, U b) {
  if (a > b) a = b;
}
template <typename T, typename U>
void amax(T& a, U b) {
  if (a < b) a = b;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
void solve() {
  long long n;
  cin >> n;
  map<string, long long> m;
  long long ans = 1;
  m["polycarp"] = 1;
  while (n--) {
    string s[3];
    for (long long i = 0; i < 3; i++) cin >> s[i];
    transform(s[0].begin(), s[0].end(), s[0].begin(), ::tolower);
    transform(s[2].begin(), s[2].end(), s[2].begin(), ::tolower);
    m[s[0]] = m[s[2]] + 1;
    amax(ans, m[s[0]]);
  }
  cout << ans << "\n";
}
void input() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  input();
  int i = 1;
  { solve(); }
}
