#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
long long month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const long long dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const long long dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const long long dx[] = {-1, 0, 1, 0};
const long long dy[] = {0, 1, 0, -1};
const long double pie = 3.1415926535897932384626;
const long long mod = 1e9 + 7;
void a_b_c() {}
void solve() {
  long long n;
  cin >> n;
  map<string, long long> l;
  l["polycarp"] = 1;
  for (long long i = 0; i < n; i++) {
    string a;
    string b;
    string c;
    cin >> a >> b >> c;
    transform(a.begin(), a.end(), a.begin(), ::tolower);
    transform(c.begin(), c.end(), c.begin(), ::tolower);
    l[a] = l[c] + 1;
  }
  long long maxi = 0;
  for (auto i : l) {
    maxi = max(maxi, i.second);
  }
  cout << maxi;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long i = 1; i <= t; i++) solve();
}
