#include <bits/stdc++.h>
using namespace std;
int n, rez = 1, br = 0;
string s[220], p, x;
map<string, vector<string>> m;
void dfs(string l) {
  br++;
  for (int i = 0; i < m[l].size(); i++) dfs(m[l][i]);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> x >> p;
    transform(s[i].begin(), s[i].end(), s[i].begin(), ::tolower);
    transform(p.begin(), p.end(), p.begin(), ::tolower);
    m[s[i]].push_back(p);
  }
  for (int i = n; i >= 1; i--) {
    br = 0;
    dfs(s[i]);
    rez = max(rez, br);
  }
  cout << rez;
  return 0;
}
