#include <bits/stdc++.h>
using namespace std;
long double PI = 3.14159265358979323846;
struct Point {
  long long x, y;
};
void volodya22() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.precision(20);
  cout << fixed;
}
long long n;
const long long N = 1e6;
const long long INF = 1e18 + 7;
const long long MOD = 1e9 + 7;
map<string, long long> mp;
void input() {
  cin >> n;
  mp["polycarp"]++;
  for (long long i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b >> b;
    std::transform(a.begin(), a.end(), a.begin(), ::tolower);
    std::transform(b.begin(), b.end(), b.begin(), ::tolower);
    mp[a] = mp[b] + 1;
  }
}
void solve() {
  long long m = 0;
  for (auto& i : mp) m = max(m, i.second);
  cout << m << "\n";
}
signed main() {
  volodya22();
  input();
  solve();
}
