#include <bits/stdc++.h>
using namespace std;
void parseArray(long long* A, long long n) {
  for (long long K = 0; K < n; K++) {
    cin >> A[K];
  }
}
long long modInverse(long long a, long long b) {
  return 1 < a ? b - modInverse(b % a, a) * b / a : 1;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long double dist(long long x, long long y, long long a, long long b) {
  return sqrt((x - a) * (x - a) + (y - b) * (y - b));
}
void debug(long long* a, long long n) {
  for (int k = 0; k < n; k++) {
    cout << a[k] << " ";
  }
  cerr << "\n";
}
vector<int> edges[1001];
unordered_map<int, string> mp1;
unordered_map<string, int> mp2;
vector<int> dp;
long long visited[5001];
int depth;
string ignore_case(string& s) {
  for (int i = 0; i < ((int)s.size()); i++) {
    s[i] = tolower(s[i]);
  }
  return s;
}
void dfs(int nd, int d) {
  if (visited[nd] == 1)
    return;
  else {
    visited[nd] = 1;
    int x = d + 1;
    if (edges[nd].size() == 1 && nd != 1) {
      dp.push_back(x);
      return;
    }
    for (auto a : edges[nd]) {
      dfs(a, x);
    }
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  string s1, s, s2;
  cin >> n;
  mp2["polycarp"] = 1;
  mp1[1] = "polycarp";
  int id(2);
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s >> s2;
    if (mp2[ignore_case(s1)] == 0) {
      mp1[id] = ignore_case(s1);
      mp2[ignore_case(s1)] = id;
      id++;
    }
    if (mp2[ignore_case(s2)] == 0) {
      mp1[id] = ignore_case(s2);
      mp2[ignore_case(s2)] = id;
      id++;
    }
    edges[mp2[ignore_case(s1)]].push_back(mp2[ignore_case(s2)]);
    edges[mp2[ignore_case(s2)]].push_back(mp2[ignore_case(s1)]);
  }
  dfs(1, depth);
  sort(dp.begin(), dp.end());
  cout << dp[dp.size() - 1] << endl;
  return 0;
}
