#include <bits/stdc++.h>
using namespace std;
const int MAX = 7009, N = 26;
vector<int> nxt[2][MAX][N];
int father[2][MAX], fchar[2][MAX], n, sz[2];
long long ans = 1;
void dfs(int c1, int c2) {
  ans++;
  int n2 = father[1][c2];
  if (n2 < 0) return;
  int cc = fchar[1][c2];
  vector<int> v = nxt[0][c1][cc];
  for (int w = 0; w < v.size(); w++) dfs(v[w], n2);
}
int main() {
  memset(father, -1, sizeof father), memset(fchar, -1, sizeof fchar);
  cin >> n;
  sz[0] = sz[1] = 1;
  for (int i = 0; i < n; i++) {
    int t, v, c;
    char ch;
    cin >> t >> v >> ch;
    t--, v--;
    c = ch - 'a';
    int add = sz[t]++;
    nxt[t][v][c].push_back(add);
    father[t][add] = v, fchar[t][add] = c;
    if (!t) {
      string s;
      for (int curr = add; curr > 0; curr = father[0][curr])
        s += fchar[0][curr];
      reverse(s.begin(), s.end());
      for (int u = 0; u < sz[1]; u++) {
        int curr = u;
        for (int q = 0; q < s.size(); q++) {
          if (fchar[1][curr] != s[q]) {
            curr = -1;
            break;
          }
          curr = father[1][curr];
        }
        if (curr >= 0) ans++;
      }
    } else
      dfs(0, add);
    cout << ans << '\n';
  }
  return 0;
}
