#include <bits/stdc++.h>
using namespace std;
int traverse(int source, vector<int> adj[], int old) {
  int a = 1;
  int k = 0;
  for (int i = 0; i < adj[source].size(); i++) {
    if (adj[source][i] != old) {
      k = max(k, traverse(adj[source][i], adj, source));
    }
  }
  return a + k;
}
string upper(string x) {
  for (int i = 0; i < x.length(); i++) x[i] = tolower(x[i]);
  return x;
}
int main() {
  int n;
  cin >> n;
  map<string, int> A;
  vector<int> adj[2 * n + 2];
  int k = 1;
  string a, b, c;
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> c;
    a = upper(a);
    c = upper(c);
    if (A[a] == 0) {
      A[a] = k;
      k++;
    }
    if (A[c] == 0) {
      A[c] = k;
      k++;
    }
    adj[A[a]].push_back(A[c]);
    adj[A[c]].push_back(A[a]);
  }
  cout << traverse(A["polycarp"], adj, -1);
}
