#include <bits/stdc++.h>
const int minINF = 1e5;
const int INF = 1e9;
const long long INFL = 1e18;
const int MAX = 1e5 + 100;
bool prime(int n) {
  if (n <= 1) return false;
  if (n == 2) return true;
  for (int x = 2; x * x <= n; x++) {
    if (n % x == 0) return false;
  }
  return true;
}
using namespace std;
int idir[] = {-1, 0, 1, 0};
int jdir[] = {0, 1, 0, -1};
int n, m;
vector<int> graph[205];
bool visited[205];
map<string, int> ma;
int inde = 1;
int getIndex(string s) {
  if (ma.count(s)) {
    return ma[s];
  } else {
    ma[s] = inde;
    inde++;
    return ma[s];
  }
}
int res = 0;
int DFS(int a) {
  if (visited[a]) return 0;
  visited[a] = true;
  for (auto u : graph[a]) {
    return 1 + DFS(u);
  }
}
void changit(string& s) {
  for (int i = 0; i < s.length(); i++) {
    if (isalpha(s[i]) and isupper(s[i])) {
      s[i] = tolower(s[i]);
    }
  }
}
int main() {
  cin >> n;
  int ans = 1;
  ma["polycarp"] = 1;
  for (int i = 0; i < n; i++) {
    string s1, t1, s2;
    cin >> s1 >> t1 >> s2;
    changit(s1);
    changit(s2);
    int e = ma[s2] + 1;
    if (e > ans) ans = e;
    ma[s1] = e;
  }
  cout << ans;
}
