#include <bits/stdc++.h>
using namespace std;
vector<int> v[205];
vector<int> h(205, 0);
void doit(int s, int par) {
  if (par != -1) {
    h[s] = 1 + h[par];
  }
  for (int i = 0; i < v[s].size(); i++) {
    if (v[s][i] == par) continue;
    doit(v[s][i], s);
  }
}
string pre(string s) {
  string tmp;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      tmp.push_back((char)((97 + s[i] - 'A')));
    } else {
      tmp.push_back(s[i]);
    }
  }
  return tmp;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  map<string, int> p;
  int k = 0;
  vector<string> tmp[n];
  for (int i = 0; i < n; i++) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    s1 = pre(s1);
    s2 = pre(s2);
    s3 = pre(s3);
    if (p.find(s3) == p.end()) {
      p.insert(make_pair(s3, k));
      k++;
    }
    if (p.find(s1) == p.end()) {
      p.insert(make_pair(s1, k));
      k++;
    }
    tmp[i].push_back(s1);
    tmp[i].push_back(s3);
  }
  for (int i = 0; i < n; i++) {
    string s1 = tmp[i][0];
    string s2 = tmp[i][1];
    int x = p[s1];
    int y = p[s2];
    v[x].push_back(y);
    v[y].push_back(x);
  }
  h[0] = 1;
  doit(0, -1);
  int ans = INT_MIN;
  for (int i = 0; i < 205; i++) ans = max(ans, h[i]);
  cout << ans;
  return 0;
}
