#include <bits/stdc++.h>
using namespace std;
const int q = 1e9;
bool visit[100009] = {false};
long long int val[100009], m, ans;
string LOW(string s) {
  for (int i = 0; i < s.size(); i++) {
    s[i] = tolower(s[i]);
  }
  return s;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int n, t, l, x, d, y = 0, r = 0, k, w, a[100009], b[100009], i = 0,
                               j = 0, flag = 0, cnt = 0, temp = 0, e = -1e4, p,
                               c, o = 0;
  cin >> n;
  map<string, long long int> v;
  string s, s2, s3;
  s = "polycarp";
  v[s] = 1;
  for (i = 0; i < n; i++) {
    cin >> s >> s2 >> s3;
    s = LOW(s);
    s3 = LOW(s3);
    v[s] = v[s3] + 1;
    ans = max(ans, v[s]);
  }
  cout << ans;
  return 0;
}
