#include <bits/stdc++.h>
using namespace std;
ifstream fin("input.txt");
ofstream fout("output.txt");
vector<int> adj[100001];
vector<int> vis(100001, 0);
long long pows(int a, int b) {
  long long res = 1;
  for (int i = 0; i < b; ++i) {
    res *= a;
  }
  return res;
}
int maxi = -1;
void dfs(int s, int steps) {
  if (vis[s]) return;
  vis[s] = 1;
  maxi = max(maxi, steps);
  for (auto x : adj[s]) dfs(x, steps + 1);
}
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  map<string, int> mps;
  int n;
  cin >> n;
  int i = 1;
  while (n--) {
    string x, y, z;
    cin >> x >> y >> z;
    transform(x.begin(), x.end(), x.begin(), ::tolower);
    transform(z.begin(), z.end(), z.begin(), ::tolower);
    if (mps.find(z) == mps.end()) mps[z] = i++;
    if (mps.find(x) == mps.end()) mps[x] = i++;
    adj[mps[z]].push_back(mps[x]);
    adj[mps[x]].push_back(mps[z]);
  }
  dfs(1, 0);
  cout << maxi + 1 << "\n";
}
