#include <bits/stdc++.h>
int main() {
  std::map<std::string, int> users{std::make_pair("polycarp", 1)};
  int n = -1;
  std::string a, b, aaa;
  while ((n < 0 ? std::cin >> n, n-- : (n == 0) ? std::cout << users["kurac"],
          false : n--) &&
         std::cin >> a >> aaa >> b &&
         (users["kurac"] =
              (std::transform(a.begin(), a.end(), a.begin(), ::tolower) !=
                   a.begin() &&
               std::transform(b.begin(), b.end(), b.begin(), ::tolower) !=
                   b.begin())
                  ? ((users.find("kurac") != users.end())
                         ? (((users[a] = users[b] + 1) > users["kurac"])
                                ? users[a]
                                : users["kurac"])
                         : 1)
                  : 1))
    ;
}
