#include <bits/stdc++.h>
using namespace std;
int n;
string a, R, b;
map<string, int> d;
int m = 0;
string toH(string inp) {
  for (int i = 0; i <= inp.size(); i++) {
    if (inp[i] > 'Z') inp[i] -= 'a' - 'A';
  }
  return inp;
}
string toL(string inp) {
  for (int i = 0; i <= inp.size(); i++) {
    if (inp[i] < 'a') inp[i] += 'a' - 'A';
  }
  return inp;
}
void read() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a >> R >> b;
    a = toL(a);
    b = toL(b);
    d[a] = d[b] + 1;
    m = max(m, d[a]);
  }
}
int main() {
  d[toL("Polycarp")] = 1;
  read();
  cout << m;
  return 0;
}
