#include <bits/stdc++.h>
using namespace std;
string s;
long long t1, t2;
vector<long long> v1[1000];
void convert() {
  long long i;
  for (i = 0; i < s.size();) {
    if (s[i] >= 65 && s[i] <= 90 || s[i] >= 48 && s[i] <= 57) {
      i++;
      continue;
    } else if (s[i] >= 97 && s[i] <= 122) {
      s[i] = s[i] - 32;
      i++;
    } else if (s[i] == ' ') {
      t1 = i - 1;
      i = i + 10;
      t2 = i;
    }
  }
}
long long length = 1;
vector<long long> v2;
void dfs(long long temp) {
  long long flag = 0;
  for (auto x : v1[temp]) {
    flag = 1;
    length++;
    dfs(x);
  }
  if (flag == 0) {
    v2.push_back(length);
  }
  length--;
}
void solve() {
  long long i, n, count = 1;
  map<string, long long> m1;
  map<string, long long> m2;
  cin >> n;
  for (i = 0; i <= n; i++) {
    getline(cin, s);
    convert();
    string s1 = s.substr(0, t1 + 1);
    string s2 = s.substr(t2, s.size() - 1);
    if (i == 1) {
      m1[s2] = count;
      m1[s1] = count + 1;
      count = count + 2;
      v1[m1[s2]].push_back(m1[s1]);
    } else if (i >= 1) {
      m1[s1] = count;
      count++;
      v1[m1[s2]].push_back(m1[s1]);
    }
  }
  dfs(1);
  cout << *max_element(v2.begin(), v2.end());
}
int main() {
  solve();
  return 0;
}
