#include <bits/stdc++.h>
using namespace std;
string cal(string s) {
  for (int i = 0; i < s.length(); i++)
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = 'a' + s[i] - 'A';
  return s;
}
vector<int> gr[201];
map<string, int> ma;
bool vit[201];
int main() {
  int n, i, cnt = 0, x, y, ret;
  string a, b, c;
  cin >> n;
  while (n--) {
    cin >> c >> b >> a;
    a = cal(a);
    c = cal(c);
    if (ma[a])
      x = ma[a];
    else {
      x = ++cnt;
      ma[a] = x;
    }
    if (ma[c])
      y = ma[c];
    else {
      y = ++cnt;
      ma[c] = y;
    }
    gr[x].push_back(y);
  }
  queue<pair<int, int> > qe;
  qe.push(make_pair(ma["polycarp"], 1));
  while (!qe.empty()) {
    pair<int, int> p = qe.front();
    qe.pop();
    ret = p.second;
    x = p.first;
    for (i = 0; i < gr[x].size(); i++) {
      y = gr[x][i];
      if (!vit[y]) {
        vit[y] = true;
        qe.push(make_pair(y, ret + 1));
      }
    }
  }
  printf("%d", ret);
  return 0;
}
