#include <bits/stdc++.h>
using namespace std;
bool flag[1000];
int sum = 0;
vector<int> a[1000];
int b = 0;
int uni = 0;
int dfs(int n) {
  b++;
  if (b > uni) {
    uni = b;
  }
  flag[n] = 1;
  for (int i = 0; i < a[n].size(); i++) {
    if (flag[a[n][i]] == 0) {
      dfs(a[n][i]);
    }
  }
  b--;
  return uni;
}
int main() {
  int n;
  cin >> n;
  pair<string, int> s[(2 * n) + 2];
  string c, h, f;
  int q = 0, d = 0, z = 0;
  for (int i = 0; i < n; i++) {
    cin >> c >> h >> f;
    for (int k = 0; k < max(c.length(), f.length()); k++) {
      if (int(c[k]) >= 65 && int(c[k]) <= 90 && k < c.length()) {
        int d = int(c[k]) + 32;
        c[k] = char(d);
      }
      if (int(f[k]) >= 65 && int(f[k]) <= 90 && k < f.length()) {
        int d = int(f[k]) + 32;
        f[k] = char(d);
      }
    }
    for (int j = 0; j < q; j++) {
      if (c == s[j].first) {
        for (int l = 0; l < q; l++) {
          if (f == s[l].first) {
            a[s[j].second].push_back(s[l].second);
            a[s[l].second].push_back(s[j].second);
            d++;
            break;
          }
        }
        if (d == 0) {
          s[q].first = f;
          s[q].second = q + 1;
          a[s[j].second].push_back(q + 1);
          a[q + 1].push_back(s[j].second);
          q++;
        }
        z++;
        break;
      }
    }
    if (z == 0) {
      d = 0;
      s[q].first = c;
      s[q].second = q + 1;
      q++;
      for (int l = 0; l < q; l++) {
        if (f == s[l].first) {
          a[q].push_back(s[l].second);
          a[s[l].second].push_back(q);
          d++;
          break;
        }
      }
      if (d == 0) {
        s[q].first = f;
        s[q].second = q + 1;
        a[q].push_back(q + 1);
        a[q + 1].push_back(q);
        q++;
      }
    }
    z = 0;
    d = 0;
  }
  cout << dfs(2);
  return 0;
}
