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