#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first > b.first);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int vis[300];
int dis[300];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, k = 1;
  cin >> n;
  map<string, int> m;
  string a, b, c;
  m["polycarp"] = 0;
  vector<int> v[n + 1];
  for (long long int j = 0; j < n; j++) {
    cin >> a >> b >> c;
    for (long long int i = 0; i < a.size(); i++) {
      a[i] = tolower(a[i]);
    }
    for (long long int i = 0; i < c.size(); i++) {
      c[i] = tolower(c[i]);
    }
    m[a] = k;
    k++;
    v[m[c]].push_back(m[a]);
  }
  queue<int> q;
  q.push(0);
  vis[0] = 1;
  dis[0] = 1;
  int max = 1;
  while (!q.empty()) {
    k = q.front();
    q.pop();
    for (long long int i = 0; i < v[k].size(); i++) {
      if (vis[v[k][i]] == 0) {
        vis[v[k][i]] = 1;
        dis[v[k][i]] = dis[k] + 1;
        if (dis[v[k][i]] > max) max = dis[v[k][i]];
        q.push(v[k][i]);
      }
    }
  }
  cout << max;
  return 0;
}
