#include <bits/stdc++.h>
using namespace std;
map<string, long long int> mp;
vector<long long int> v[250], v1;
long long int level[250];
void dfs(long long int a) {
  if (v[a].size() == 0) {
    v1.push_back(level[a]);
  }
  for (long long int i = 0; i < v[a].size(); i++) {
    long long int s = v[a][i];
    level[s] = level[a] + 1;
    dfs(s);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int a, i, c = 1, mx = 0;
  string s1, s2, s3;
  cin >> a;
  for (i = 0; i < a; i++) {
    cin >> s1 >> s2 >> s3;
    transform(s1.begin(), s1.end(), s1.begin(), ::toupper);
    transform(s3.begin(), s3.end(), s3.begin(), ::toupper);
    if (mp[s1] == 0) {
      mp[s1] = c;
      c++;
    }
    if (mp[s3] == 0) {
      mp[s3] = c;
      c++;
    }
    long long int p = mp[s1];
    long long int q = mp[s3];
    v[q].push_back(p);
  }
  for (i = 0; i < v[2].size(); i++) {
    long long int m = v[2][i];
    level[m] = 2;
    dfs(m);
  }
  cout << *max_element(v1.begin(), v1.end());
  return 0;
}
