#include <bits/stdc++.h>
using namespace std;
map<string, int> ma;
vector<int> ind;
vector<int> adj[205];
string x[205], y;
int vis[205], ht[205];
void dfs(int u) {
  vis[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int cur = adj[u][i];
    if (!vis[cur]) {
      vis[cur] = 1;
      ht[cur] = ht[u] + 1;
      dfs(cur);
    }
  }
}
int main() {
  int n;
  string str[205];
  cin >> n;
  for (int i = 0; i < n + 1; i++) {
    getline(cin, str[i]);
    transform(str[i].begin(), str[i].end(), str[i].begin(), ::tolower);
  }
  string z[100];
  ma["polycarp"] = 1;
  int k = 2;
  ht[1] = 1;
  for (int i = 1; i < n + 1; i++) {
    for (int j = 0; j < str[i].size(); j++) {
      if (str[i][j] == ' ') ind.push_back(j);
    }
    x[i] = str[i].substr(0, ind[0]);
    y = str[i].substr(ind[0] + 1, ind[1] - ind[0] - 1);
    z[i] = str[i].substr(ind[1] + 1, str[i].size() - ind[1]);
    if (!ma[x[i]]) ma[x[i]] = k, k++;
    if (!ma[z[i]]) ma[z[i]] = k, k++;
    ind.clear();
  }
  for (int i = 1; i < n + 1; i++) {
    adj[ma[z[i]]].push_back(ma[x[i]]);
  }
  dfs(1);
  int *max1;
  max1 = max_element(ht + 1, ht + 205);
  cout << *max1 << "\n";
  return 0;
}
