#include <bits/stdc++.h>
using namespace std;
string f(string s) {
  string ans = "";
  for (char ch : s) {
    if (ch >= 'A' and ch <= 'Z') ch = ch - 'A' + 'a';
    ans += ch;
  }
  return ans;
}
int height(unordered_map<string, vector<string>> &m, string root) {
  if (m[root].size() == 0) {
    return 1;
  }
  int maxHeight = INT_MIN;
  for (string child : m[root]) {
    maxHeight = max(maxHeight, height(m, child));
  }
  int ans = maxHeight + 1;
  return ans;
}
int main() {
  int n;
  cin >> n;
  unordered_map<string, vector<string>> m;
  for (int i = 0; i < n; i++) {
    string name1, reposted, name2;
    cin >> name1 >> reposted >> name2;
    m[f(name2)].push_back(f(name1));
  }
  int ans = height(m, f("Polycarp"));
  cout << ans;
}
