#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 1, MOD = 1e9 + 7;
int n, sz;
vector<int> g[N], str;
bool vis[N];
map<string, int> mp;
void change(string &x) {
  for (int i = 0; i < x.size(); ++i) x[i] = tolower(x[i]);
}
int an;
void bfs(int current) {
  vis[current] = true;
  queue<pair<int, int> > q;
  q.push(make_pair(current, 1));
  while (!q.empty()) {
    current = q.front().first;
    int dpth = q.front().second;
    q.pop();
    an = max(an, dpth);
    for (int i = 0; i < g[current].size(); ++i) {
      int u = g[current][i];
      if (!vis[u]) {
        q.push(make_pair(u, dpth + 1));
        vis[u] = true;
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  int lst = 0;
  for (int i = 0; i < n; ++i) {
    string a, tmp, b;
    cin >> a >> tmp >> b;
    change(a);
    change(b);
    if (!mp[a]) {
      mp[a] = ++lst;
    }
    if (!mp[b]) {
      mp[b] = ++lst;
    }
    g[mp[b]].push_back(mp[a]);
  }
  bfs(2);
  cout << an;
}
