#include <bits/stdc++.h>
long long gi() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) f ^= ch == '-', ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return f ? x : -x;
}
char S[600010];
int n, W[600010], nxt[600010], dnxt[600010];
std::map<int, int> mp;
int t[600010];
void update(int x, int d) {
  while (x <= n) t[x] += d, x += x & -x;
}
int query(int x) {
  int r = 0;
  while (x) r += t[x], x -= x & -x;
  return r;
}
int ANS[50];
void Inc(long long x, int p = 1) {
  if (x) ANS[p] += x % 10, Inc(x / 10, p + 1);
}
int main() {
  n = gi();
  unsigned long long sum = 0, ans = 0;
  int s26 = 0, a26 = 0;
  mp[0] = -1;
  for (int i = 1; i <= n; ++i) {
    S[i] = ((getchar() - 'a' + a26) % 26 + 26) % 26 + 'a';
    W[i] = gi() ^ ((ans & ((1 << 30) - 1)));
    while (mp.rbegin()->second >= W[i]) {
      sum += 1ll * (query(mp.rbegin()->first) - query((++mp.rbegin())->first)) *
             (W[i] - mp.rbegin()->second);
      s26 = (s26 +
             1ll * (query(mp.rbegin()->first) - query((++mp.rbegin())->first)) *
                 (W[i] - mp.rbegin()->second)) %
            26;
      mp.erase(--mp.end());
    }
    mp[i] = W[i];
    int p = nxt[i - 1];
    while (p && S[p + 1] != S[i]) p = nxt[p];
    if (S[p + 1] == S[i]) ++p;
    nxt[i] = p;
    if (i == 1) nxt[i] = 0;
    if (i > 1)
      dnxt[i - 1] = (S[i] == S[nxt[i - 1] + 1] ? dnxt[nxt[i - 1]] : nxt[i - 1]);
    p = i - 1;
    if (S[i] == S[1]) update(i, 1), sum += W[i], s26 = (s26 + W[i]) % 26;
    while (p) {
      if (S[p + 1] == S[i])
        p = dnxt[p];
      else {
        int q = i - p;
        assert(query(q) ^ query(q - 1));
        update(q, -1);
        sum -= mp.lower_bound(q)->second;
        s26 = (s26 - mp.lower_bound(q)->second) % 26 + 26;
        p = nxt[p];
      }
    }
    a26 = (a26 + s26) % 26;
    ans += sum;
    Inc(sum);
    for (int i = 1; i <= 40; ++i) ANS[i + 1] += ANS[i] / 10, ANS[i] %= 10;
    int w = 1;
    for (int i = 1; i <= 40; ++i)
      if (ANS[i]) w = i;
    for (int i = w; i; --i) putchar(ANS[i] + '0');
    puts("");
  }
  return 0;
}
