#include <bits/stdc++.h>
using namespace std;
long long mod(long long n) { return n % (long long)1000000007; }
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int main() {
  long long n;
  cin >> n;
  map<string, long long> m;
  long long ans = 0;
  for (long long i = 1; i < n + 1; i = i + 1) {
    string a, c, b;
    cin >> a >> c >> b;
    for (long long i = 0; i < a.length(); i = i + 1) {
      if (a[i] >= 65 && a[i] <= 90) {
        a[i] = a[i] + 32;
      }
    }
    for (long long i = 0; i < b.length(); i = i + 1) {
      if (b[i] >= 65 && b[i] <= 90) {
        b[i] = b[i] + 32;
      }
    }
    m[a] += m[b] + 1;
    ans = max(ans, m[a]);
  }
  cout << ans + 1;
}
