#include <bits/stdc++.h>
using namespace std;
const int N = 611111, MASK = (1 << 30) - 1;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  bool f = false;
  for (; ch < '0' || ch > '9'; ch = getchar()) f |= ch == '-';
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
  if (f) x = -x;
}
void read(char &x) {
  do x = getchar();
  while (x < 'a' && x > 'z');
}
template <typename T>
void write(T x) {
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
int n, val[N], nxt[N], stk[N], tp = 1, anc[N];
char str[N];
long long sum;
map<int, int> buc;
__int128 ans;
int main() {
  read(n);
  read(str[0]);
  read(val[0]);
  write(ans = sum = val[0]);
  buc[val[0]] = 1;
  for (int i = 1, j = 0; i < n; ++i) {
    read(str[i]);
    read(val[i]);
    val[i] ^= ans & MASK;
    str[i] = (str[i] - 'a' + ans) % 26 + 'a';
    while (j && str[i] != str[j]) j = nxt[j];
    if (str[i] == str[j]) ++j;
    nxt[i + 1] = j;
    anc[i] = (str[i] == str[nxt[i]]) ? anc[nxt[i]] : nxt[i];
    int now = anc[i];
    while (now) {
      if (str[now] == str[i])
        now = anc[now];
      else {
        int tmp = val[*lower_bound(stk, stk + tp, i - now)];
        --buc[tmp];
        sum -= tmp;
        if (!buc[tmp]) buc.erase(tmp);
        now = nxt[now];
      }
    }
    if (str[0] == str[i]) {
      ++buc[val[i]];
      sum += val[i];
    }
    while (tp && val[stk[tp - 1]] >= val[i]) --tp;
    stk[tp++] = i;
    int tmp = 0;
    for (auto it = buc.upper_bound(val[i]); it != buc.end();
         ++it, buc.erase(prev(it))) {
      sum -= (long long)(it->first - val[i]) * it->second;
      tmp += it->second;
    }
    buc[val[i]] += tmp;
    putchar('\n');
    write(ans += sum);
  }
}
