#include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
inline int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
string to_str(T str) {
  stringstream stream;
  stream << str;
  return stream.str();
}
template <typename T>
int to_int(T num) {
  int val;
  stringstream stream;
  stream << num;
  stream >> val;
  return val;
}
vector<string> split(const string& s, char delim) {
  vector<string> elems;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) elems.push_back(item);
  return elems;
}
const int dr[] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int T2 = 105;
const int T3 = 1005;
const int T4 = 10005;
const int T5 = 100005;
int mx;
int main() {
  int n;
  cin >> n;
  map<string, int> p;
  p["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; a[i]; i++) {
      if (a[i] >= 'A' && a[i] <= 'Z') a[i] += 32;
    }
    for (int i = 0; c[i]; i++) {
      if (c[i] >= 'A' && c[i] <= 'Z') c[i] += 32;
    }
    p[a] = p[c] + 1;
    mx = max(mx, p[a]);
  }
  cout << mx << "\n";
  return 0;
}
