#include <bits/stdc++.h>
using namespace std;
unordered_map<string, int> mp;
vector<int> g[201];
bool visited[201];
void convert(string &a) {
  for (auto &e : a) e = tolower(e);
}
bool check(const string &a) {
  if (mp.count(a) == 0) return false;
  return true;
}
int cnt = 1, ans = 2;
void dfs(int start) {
  visited[start] = 1;
  ans = max(cnt, ans);
  for (int i = 0; i < g[start].size(); ++i) {
    if (!visited[g[start][i]]) {
      ++cnt;
      dfs(g[start][i]);
      --cnt;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  int poly = -1;
  for (int i = 0, node = 0; i < n; ++i) {
    string a, rep, b;
    cin >> a >> rep >> b;
    convert(b);
    convert(a);
    bool b1 = check(b), b2 = check(a);
    if (b1 && b2) {
      g[mp[b]].emplace_back(mp[a]);
    } else if (b1 && !b2) {
      mp[a] = node;
      g[mp[b]].emplace_back(node);
      ++node;
    } else if (!b1 && b2) {
      mp[b] = node;
      g[node].emplace_back(mp[a]);
      ++node;
    } else if (!b1 && !b2) {
      mp[b] = node;
      ++node;
      mp[a] = node;
      ++node;
      g[mp[b]].emplace_back(mp[a]);
    }
    if (b == "polycarp") poly = mp[b];
    if (a == "polycarp") poly = mp[a];
  }
  dfs(poly);
  cout << ans << '\n';
  return 0;
}
