#include <bits/stdc++.h>
using namespace std;
int n, q = 1, ans;
map<string, int> x;
int g[500][500];
bool used[500];
string down(string s) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] += 32;
  }
  return s;
}
void dfs(int v, int cnt) {
  ans = max(cnt, ans);
  used[v] = true;
  for (int i = 1; i <= q; i++) {
    if (g[v][i] && !used[i]) dfs(i, cnt + 1);
  }
}
int main() {
  cin >> n;
  x["polycarp"] = 1;
  for (int i = 1; i <= n; i++) {
    string a, b;
    cin >> a >> b >> b;
    a = down(a);
    b = down(b);
    if (!x[a]) x[a] = ++q;
    if (!x[b]) x[b] = ++q;
    g[x[b]][x[a]] = 1;
  }
  dfs(1, 1);
  cout << ans;
}
