#include <bits/stdc++.h>
using namespace std;
int tr[600010 << 2];
void modify(int rt, int l, int r, int pos, int v) {
  if (l == r) {
    tr[rt] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(rt << 1, l, mid, pos, v);
  else
    modify(rt << 1 | 1, mid + 1, r, pos, v);
  tr[rt] = min(tr[rt << 1], tr[rt << 1 | 1]);
}
int query(int rt, int l, int r, int L, int R) {
  if (L <= l && R >= r) return tr[rt];
  int mid = (l + r) >> 1, ret = 2000000000;
  if (L <= mid) ret = min(ret, query(rt << 1, l, mid, L, R));
  if (R > mid) ret = min(ret, query(rt << 1 | 1, mid + 1, r, L, R));
  return ret;
}
int n;
char s[10];
int c, w;
int a[600010], nxt[600010], jmp[600010];
map<int, int> mp;
int main() {
  scanf("%d", &n);
  unsigned long long ansL = 0, ansH = 0, ans26 = 0, ansB = 0, sum = 0;
  int j = 0;
  scanf("%s%d", s, &w);
  c = (ans26 + s[0] - 'a') % 26;
  w ^= ansB & ((1 << 30) - 1);
  modify(1, 1, n, 1, w);
  a[1] = c;
  nxt[1] = 0;
  jmp[1] = 0;
  mp[w]++;
  sum += w;
  ansL += sum;
  if (ansL >= 1000000000000000000) {
    ansL -= 1000000000000000000;
    ansH++;
  }
  ansB = (ansB + sum) & ((1 << 30) - 1);
  ans26 = (ans26 + sum) % 26;
  if (ansH)
    printf("%llu%018llu\n", ansH, ansL);
  else
    printf("%llu\n", ansL);
  for (int i = 2; i <= n; i++) {
    scanf("%s%d", s, &w);
    c = (ans26 + s[0] - 'a') % 26;
    w ^= ansB & ((1 << 30) - 1);
    modify(1, 1, n, i, w);
    a[i] = c;
    while (j && c != a[j + 1]) j = nxt[j];
    if (c == a[j + 1]) j++;
    nxt[i] = j;
    if (a[nxt[i - 1] + 1] != c)
      jmp[i - 1] = nxt[i - 1];
    else
      jmp[i - 1] = jmp[nxt[i - 1]];
    if (a[1] == c) {
      mp[w]++;
      sum += w;
    }
    int k = nxt[i - 1];
    while (k) {
      if (a[k + 1] != a[i]) {
        int v = query(1, 1, n, i - k, i - 1);
        mp[v]--;
        sum -= v;
        k = nxt[k];
        if (mp[v] == 0) mp.erase(v);
      } else
        k = jmp[k];
    }
    for (auto it = mp.upper_bound(w); it != mp.end();) {
      mp[w] += it->second;
      sum -= (unsigned long long)(it->first - w) * it->second;
      auto jt = next(it);
      mp.erase(it);
      it = jt;
    }
    ansL += sum;
    if (ansL >= 1000000000000000000) {
      ansL -= 1000000000000000000;
      ansH++;
    }
    ansB = (ansB + sum) & ((1 << 30) - 1);
    ans26 = (ans26 + sum) % 26;
    if (ansH)
      printf("%llu%018llu\n", ansH, ansL);
    else
      printf("%llu\n", ansL);
  }
  return 0;
}
