#include <bits/stdc++.h>
using namespace std;
int n;
string w;
string a;
string h;
string actual = "polycarp";
map<string, vector<string> > tree;
int dfs_search(string actual) {
  int ans = 1;
  for (auto i : tree[actual]) {
    ans = max(dfs_search(i) + 1, ans);
  }
  return ans;
}
int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cin >> w;
    cin >> h;
    for (int x = 0; x < a.length(); x++) {
      a[x] = tolower(a[x]);
    }
    for (int x = 0; x < h.length(); x++) {
      h[x] = tolower(h[x]);
    }
    tree[h].push_back(a);
  }
  cout << dfs_search(actual) << endl;
}
