#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6, MAX = 10, OO = 1000000009;
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long x, long long y) { return (x * y / gcd(x, y)); }
int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
bool valid(int i, int j) { return i >= 0 && j >= 0 && i < 8 && j < 8; }
map<string, int> mp;
int n, ans;
string a, b;
void lower(string &s) {
  for (char &i : s) i = tolower(i);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> a >> b >> b;
    lower(a), lower(b);
    mp[a] = mp[b] + 1;
    ans = max(ans, mp[a]);
  }
  printf("%d\n", ++ans);
  return 0;
}
