#include <bits/stdc++.h>
using namespace std;
const int N = 600005, inf = 2e9, MSK = (1 << 30) - 1;
const unsigned long long BS = 1000000000000000000;
int n, c, w, a[N], nxt[N], up[N], T[N << 2];
unsigned long long A0, A1, A, B, S;
char s[10];
map<int, int> mp;
void upd(int x, int l, int r, int p, int v) {
  if (l == r) {
    T[x] = v;
    return;
  }
  int mid = l + r >> 1;
  p <= mid ? upd(x << 1, l, mid, p, v) : upd(x << 1 | 1, mid + 1, r, p, v);
  T[x] = min(T[x << 1], T[x << 1 | 1]);
}
int qry(int x, int l, int r, int tl, int tr) {
  if (tl <= l && r <= tr) return T[x];
  int mid = l + r >> 1, res = inf;
  if (tl <= mid) res = min(res, qry(x << 1, l, mid, tl, tr));
  if (tr > mid) res = min(res, qry(x << 1 | 1, mid + 1, r, tl, tr));
  return res;
}
int main() {
  scanf("%d%s%d", &n, s, &w);
  c = (A + s[0] - 'a') % 26;
  w ^= B & MSK;
  upd(1, 1, n, 1, w);
  a[1] = c;
  mp[w]++;
  S += w;
  A = (A + S) % 26;
  B = (B + S) & MSK;
  A0 += S;
  if (A0 >= BS) A0 -= BS, A1++;
  if (A1)
    printf("%llu%018llu\n", A1, A0);
  else
    printf("%llu\n", A0);
  for (int i = 2, j = 0; i <= n; i++) {
    scanf("%s%d", s, &w);
    c = (A + s[0] - 'a') % 26;
    w ^= B & MSK;
    upd(1, 1, n, i, w);
    a[i] = c;
    if (a[1] == c) mp[w]++, S += w;
    while (j && c != a[j + 1]) j = nxt[j];
    if (c == a[j + 1]) j++;
    nxt[i] = j;
    up[i - 1] = a[nxt[i - 1] + 1] == c ? up[nxt[i - 1]] : nxt[i - 1];
    for (int k = nxt[i - 1]; k;) {
      if (a[k + 1] == a[i]) {
        k = up[k];
        continue;
      }
      int v = qry(1, 1, n, i - k, i - 1);
      mp[v]--;
      S -= v;
      k = nxt[k];
      if (!mp[v]) mp.erase(v);
    }
    for (auto it = mp.upper_bound(w); it != mp.end();) {
      mp[w] += it->second;
      S -= (unsigned long long)(it->first - w) * it->second;
      mp.erase(it++);
    }
    A = (A + S) % 26;
    B = (B + S) & MSK;
    A0 += S;
    if (A0 >= BS) A0 -= BS, A1++;
    if (A1)
      printf("%llu%018llu\n", A1, A0);
    else
      printf("%llu\n", A0);
  }
  return 0;
}
