#include <bits/stdc++.h>
using namespace std;
int a[100005], m, fix[100005];
map<int, int> p;
set<int> st;
vector<int> v[100005];
map<string, int> mp;
void dfs(int x, int k) {
  m = max(m, k);
  fix[x] = 1;
  for (int j = 0; j < v[x].size(); j++) {
    int to = v[x][j];
    if (!fix[to]) dfs(to, k + 1);
  }
}
int main() {
  int n, in = 2;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string a, b, c;
    cin >> a >> b >> c;
    string str = c;
    for (int j = 0; j < a.size(); j++)
      if (a[j] >= 'A' && a[j] <= 'Z') a[j] = char(a[j] - 'A' + 'a');
    for (int j = 0; j < c.size(); j++)
      if (c[j] >= 'A' && c[j] <= 'Z') c[j] = char(c[j] - 'A' + 'a');
    if (c == "polycarp") mp[c] = 1;
    if (mp[a] == 0) {
      mp[a] = in;
      in++;
    }
    if (mp[c] == 0) {
      mp[c] = in;
      in++;
    }
    int x = mp[a], y = mp[c];
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(1, 1);
  cout << m;
}
