#include <bits/stdc++.h>
using namespace std;
const int N = 600000 + 100;
const long double pi = acos(-1.0);
map<int, int> mp;
int n, jmp[N], nxt[N], str[N];
char s[5];
map<int, int>::iterator it, it2;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
namespace Segment_Tree {
int seg[N << 3];
void modify(int id, int l, int r, int p, int v) {
  if (l == r) {
    seg[id] = v;
    return;
  }
  int mid = (l + r) >> 1;
  if (p <= mid)
    modify(id << 1, l, mid, p, v);
  else
    modify(id << 1 | 1, mid + 1, r, p, v);
  seg[id] = min(seg[id << 1], seg[id << 1 | 1]);
}
int query(int id, int l, int r, int ql, int qr) {
  if ((l >= ql) && (r <= qr)) return seg[id];
  int mid = (l + r) >> 1, ans = 2e9;
  if (ql <= mid) ans = min(ans, query(id << 1, l, mid, ql, qr));
  if (qr > mid) ans = min(ans, query(id << 1 | 1, mid + 1, r, ql, qr));
  return ans;
}
}  // namespace Segment_Tree
using namespace Segment_Tree;
pair<unsigned long long, unsigned long long> ans;
void addans(unsigned long long val) {
  ans.first += val;
  if (ans.first >= 1000000000000000000) {
    ans.first -= 1000000000000000000;
    ans.second++;
  }
}
void out() {
  if (ans.second)
    printf("%llu%018llu\n", ans.second, ans.first);
  else
    printf("%llu\n", ans.first);
}
int main() {
  n = read();
  ans.first = ans.second = 0;
  unsigned long long nans = 0, ansc = 0, answ = 0;
  scanf("%s", s);
  int w = read();
  mp[w]++;
  nans += w;
  ansc = nans % 26;
  answ = (nans & ((1 << 30) - 1));
  addans(nans);
  out();
  modify(1, 1, n, 1, w);
  str[1] = s[0] - 'a';
  int j = 0;
  for (register int i = 2; i <= n; i++) {
    scanf("%s", s);
    w = read();
    int ch = (ansc + s[0] - 'a') % 26;
    w ^= answ & ((1 << 30) - 1);
    str[i] = ch;
    modify(1, 1, n, i, w);
    while ((j) && (str[j + 1] != str[i])) j = nxt[j];
    if (str[j + 1] == str[i]) j++;
    nxt[i] = j;
    if (str[i] == str[1]) {
      nans += w;
      mp[w]++;
    }
    if (str[nxt[i - 1] + 1] != str[i])
      jmp[i - 1] = nxt[i - 1];
    else
      jmp[i - 1] = jmp[nxt[i - 1]];
    int k = nxt[i - 1];
    while (k) {
      if (str[k + 1] != str[i]) {
        int val = query(1, 1, n, i - k, i - 1);
        mp[val]--;
        nans -= val;
        k = nxt[k];
        if (!mp[val]) mp.erase(val);
      } else
        k = jmp[k];
    }
    for (it = mp.upper_bound(w); it != mp.end();) {
      mp[w] += it->second;
      nans -= (unsigned long long)(it->first - w) * it->second;
      it2 = next(it);
      mp.erase(it);
      it = it2;
    }
    addans(nans);
    ansc = (ansc + nans) % 26;
    answ = (answ + nans) & ((1 << 30) - 1);
    out();
  }
  return 0;
}
