#include <bits/stdc++.h>
using namespace std;
long long int power_mod(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power_mod(a, x / 2);
  long long int ans = (y * y) % 1000000007;
  if (x % 2) ans = (ans * a) % 1000000007;
  return ans;
}
long long int inv(long long int a) { return power_mod(a, 1000000007 - 2); }
long long int power(long long int a, long long int x) {
  if (x == 0) return 1;
  long long int y = power(a, x / 2);
  long long int ans = (y * y);
  if (x % 2) ans *= a;
  return ans;
}
template <class T>
void printvec(vector<T> &a) {
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
template <class T>
void printarr(T a[], int n) {
  for (int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  unordered_map<string, int> make_pair;
  make_pair["polycarp"] = 1;
  while (n--) {
    string a, _, c;
    cin >> a >> _ >> c;
    for (int i = 0; i < a.size(); i++) {
      a[i] = tolower(a[i]);
    }
    for (int i = 0; i < c.size(); i++) {
      c[i] = tolower(c[i]);
    }
    make_pair[a] = make_pair[c] + 1;
  }
  int ans = 0;
  for (auto i = make_pair.begin(); i != make_pair.end(); i++) {
    ans = max(ans, i->second);
  }
  cout << ans << endl;
}
