#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const int N = 2e5 + 5;
const double pi = acos(-1);
vector<vector<long long> > v;
bool vis[100005];
int lvl[100005], maxx;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, k = 0;
  string s1, s2, s3;
  cin >> n;
  v.resize(n * 2 + 3);
  map<string, bool> str;
  map<string, long long> val;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::tolower);
    transform(s3.begin(), s3.end(), s3.begin(), ::tolower);
    if (!str[s1]) {
      str[s1] = true;
      val[s1] = k;
      k++;
    }
    if (!str[s3]) {
      str[s3] = true;
      val[s3] = k;
      k++;
    }
    v[val[s1]].push_back(val[s3]);
    v[val[s3]].push_back(val[s1]);
  }
  queue<long long> q;
  q.push(val["polycarp"]);
  lvl[val["polycarp"]] = 1;
  vis[val["polycarp"]] = true;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (auto i : v[cur]) {
      if (!vis[i] && i != cur) {
        vis[i] = true;
        lvl[i] = lvl[cur] + 1;
        maxx = max(maxx, lvl[i]);
        q.push(i);
      }
    }
  }
  cout << maxx << endl;
  return 0;
}
