#include <bits/stdc++.h>
using namespace std;
map<string, vector<string> > adj;
map<string, bool> vis;
map<string, int> h;
int n, maxh;
string low(string s) {
  for (int i = 0; i < s.size(); i++) s[i] = tolower(s[i]);
  return s;
}
void dfs(string v, int high = -1) {
  vis[v] = true;
  h[v] = high + 1;
  maxh = max(maxh, h[v]);
  for (int i = 0; i < adj[v].size(); i++) {
    string u = adj[v][i];
    if (!vis[u]) dfs(u, h[v]);
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    s1 = low(s1);
    s3 = low(s3);
    adj[s1].push_back(s3);
    adj[s3].push_back(s1);
  }
  dfs("polycarp");
  cout << maxh + 1;
  return 0;
}
