#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T first, T second) {
  while (second > 0) {
    first %= second;
    swap(first, second);
  }
  return first;
}
template <class _T>
inline _T sqr(const _T &first) {
  return first * first;
}
template <class _T>
inline string tostr(const _T &a) {
  ostringstream os("");
  os << a;
  return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
template <typename T>
inline void input(T &a) {
  static int c;
  a = 0;
  while (!isdigit(c = getchar()) && c != '-') {
  }
  char neg = 0;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    a = 10 * a + c - '0';
    c = getchar();
  }
  if (neg) a = -a;
}
template <typename T = int>
inline T nxt() {
  T res;
  input(res);
  return res;
}
const int N = 400;
vector<int> g[N];
int dp[N];
int solve(int first) {
  int &res = dp[first];
  if (res != -1) {
    return res;
  }
  res = 1;
  for (int v : g[first]) {
    res = max(res, 1 + solve(v));
  }
  return res;
}
int main() {
  memset(dp, 255, sizeof(dp));
  int k = nxt();
  map<string, int> id;
  id["polycarp"] = 0;
  int sz = 1;
  for (int i = 0; i < k; ++i) {
    string a, b, c;
    cin >> a >> b >> c;
    for (char &d : a) {
      d = tolower(d);
    }
    for (char &d : c) {
      d = tolower(d);
    }
    int A = id.count(a) ? id[a] : (id[a] = sz++);
    int B = id.count(c) ? id[c] : (id[c] = sz++);
    g[B].push_back(A);
  }
  cout << solve(0) << endl;
  return 0;
}
