#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:255000000")
bool firstout = 1;
template <class T>
T &minn(T &a, T b) {
  if (b < a) a = b;
  return a;
}
template <class T>
T &maxx(T &a, T b) {
  if (a < b) a = b;
  return a;
}
int &madd(int &a, int b) {
  a += b;
  if (a >= 1000000009) a -= 1000000009;
  return a;
}
int &msub(int &a, int b) {
  a -= b;
  if (a < 0) a += 1000000009;
  return a;
}
int &mmult(int &a, int b) { return a = (long long)a * b % 1000000009; }
int mdiv(long long a, long long b, long long m) {
  a = (a % m + m) % m;
  b = (b % m + m) % m;
  if (a % b == 0) return a / b;
  return (a + m * mdiv(-a, m, b)) / b;
}
char C[7012];
int P[7012];
struct bora {
  int d, dd;
  bora *A[26];
  bora() {
    int i;
    d = dd = 0;
    for (i = 0; i < 26; ++i) A[i] = NULL;
  }
  bora *add(char cc) {
    int c = cc - 'a';
    if (!A[c]) A[c] = new bora();
    ++A[c]->d;
    return A[c];
  }
  long long add(int i) {
    ++dd;
    long long res = d;
    if (P[i] == -1) return res;
    int c = C[i] - 'a';
    if (!A[c]) A[c] = new bora();
    return res + A[c]->add(P[i]);
  }
};
int n, m, q;
bora *B[7012];
int main() {
  int i, j, k;
  char c;
  int a, d;
  int ts;
  for (ts = 1; scanf("%"
                     "d",
                     &(q)) > 0;
       ++ts) {
    long long res = 1;
    n = m = 1;
    B[0] = new bora();
    B[0]->d = B[0]->dd = 1;
    P[0] = -1;
    for (; q--;) {
      char s[5];
      char &c = s[0];
      scanf(
          "%"
          "d",
          &(k));
      scanf(
          "%"
          "d",
          &(i));
      --i;
      scanf(
          "%"
          "s",
          &(s));
      if (k == 1) {
        B[n++] = B[i]->add(c);
        res += B[n - 1]->dd;
      } else {
        C[m] = c;
        P[m] = i;
        res += B[0]->add(m++);
      }
      printf(
          "%"
          "I64d",
          (res));
      printf("\n"), firstout = 1;
    }
  }
  return 0;
}
