#include <bits/stdc++.h>
using namespace std;
const int MAX = 500;
int n, id, vis[MAX];
vector<int> adjList[MAX];
map<string, int> mp;
int DFS(int u) {
  vis[u] = 0;
  int cnt = 0;
  for (int v : adjList[u])
    if (!vis[u]) cnt = max(cnt, DFS(v) + 1);
  return cnt;
}
string ToLower(string s) {
  for (int i = 0; i < s.size(); i++)
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] -= ('A' - 'a');
  return s;
}
int main() {
  memset(vis, -1, sizeof vis);
  cin >> n;
  for (int i = 0; i < n; i++) {
    string to, re, from;
    cin >> to >> re >> from;
    to = ToLower(to);
    from = ToLower(from);
    if (!mp.count(from)) mp[from] = ++id;
    if (!mp.count(to)) mp[to] = ++id;
    adjList[mp[from]].push_back(mp[to]);
  }
  cout << DFS(mp["polycarp"]) + 1;
  return 0;
}
