#include <bits/stdc++.h>
using namespace std;
long long int mi(long long int n, long long int m) {
  long long int pw = n % m;
  long long int ex = m - 2;
  long long int ans = 1;
  while (ex) {
    if (ex & 1) ans = ans * pw % m;
    pw = pw * pw % m;
    ex >>= 1;
  }
  return ans % 1000000007;
}
long long int pw(long long int a, long long int n) {
  long long int pw = a % 1000000007;
  long long int ex = n;
  long long int ans = 1;
  while (ex) {
    if (ex & 1) ans = ans * pw % 1000000007;
    pw = pw * pw % 1000000007;
    ex >>= 1;
  }
  return ans % 1000000007;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (T &t : v) is >> t;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (const T &t : v) {
    os << t << " ";
  }
  os << '\n';
  return os;
}
void show(long long int x) { cout << x << " "; }
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
long long int max(long long int a, long long int b) { return a > b ? a : b; }
long long int min(long long int a, long long int b) { return a < b ? a : b; }
long long int Abs(long long int x) { return x > 0 ? x : (-x); }
long long int Ceil(long long int a, long long int b) {
  return a / b + (a % b != 0);
}
map<string, vector<string>> adj;
map<string, long long int> dp;
void dfs(string v, string par) {
  long long int M = 0;
  for (string nbs : adj[v]) {
    if (nbs != par) {
      dfs(nbs, v);
      M = max(M, dp[nbs]);
    }
  }
  dp[v] = M + 1;
}
void solve() {
  long long int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    for_each(s1.begin(), s1.end(), [](char &c) { c = ::tolower(c); });
    for_each(s3.begin(), s3.end(), [](char &c) { c = ::tolower(c); });
    adj[s1].push_back(s3);
    adj[s3].push_back(s1);
  }
  string root = "polycarp";
  dfs(root, "-1");
  cout << dp[root];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t = 1;
  while (t--) {
    solve();
  }
}
