#include <bits/stdc++.h>
using namespace std;
class node {
 public:
  string data;
  vector<node*> children;
  node(string x) { data = x; }
};
void insert(node* root, string parent, string child) {
  if (root->data == parent) {
    root->children.push_back(new node(child));
    return;
  } else {
    queue<node*> q;
    int no_of_chidrens = root->children.size();
    for (int i = 0; i < no_of_chidrens; i++) {
      if (root->children[i]->data == parent)
        insert(root->children[i], parent, child);
      else
        q.push(root->children[i]);
    }
    while (q.size() > 0) {
      insert(q.front(), parent, child);
      q.pop();
    }
  }
}
int height(node* root) {
  if (root == NULL) return 0;
  if (root->children.size() == 0) return 1;
  int max = -90;
  for (int i = 0; i < root->children.size(); i++) {
    int x = height(root->children[i]);
    if (x > max) max = x;
  }
  return max + 1;
}
void traversal(node* root) {
  queue<node*> q;
  if (root == NULL) return;
  cout << "children of " << root->data << " are : ";
  for (int i = 0; i < root->children.size(); i++) {
    cout << root->children[i]->data << " ";
    q.push(root->children[i]);
  }
  cout << endl;
  while (q.size() > 0) {
    traversal(q.front());
    q.pop();
  }
}
int main() {
  int n;
  cin >> n;
  string posts[n], input, parent, child;
  node* root = new node("polycarp");
  cin.ignore();
  for (int i = 0; i < n; i++) {
    getline(cin, input);
    transform(input.begin(), input.end(), input.begin(), ::tolower);
    stringstream s(input);
    s >> child;
    s >> input;
    s >> parent;
    insert(root, parent, child);
  }
  cout << height(root);
}
