#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  bool flag = false;
  while (!isdigit(c)) {
    if (c == '-') flag = true;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  if (flag) x = -x;
}
int n, root = 1, pos;
long long val;
int s[600010], w[600010], nxt[600010], col[600010], fa[600010][28], st[600010],
    mn[2400010];
char c[5];
map<long long, int> mp;
pair<long long, long long> ans;
pair<long long, long long> operator+(const pair<long long, long long> &x,
                                     const long long &y) {
  return make_pair((x.first + y) % 1000000000000000000,
                   x.second + (x.first + y) / 1000000000000000000);
}
long long operator%(const pair<long long, long long> &x, const long long &p) {
  return (x.first % p + (x.second % p) * (1000000000000000000 % p) % p) % p;
}
void write(pair<long long, long long> x) {
  if (x.second)
    printf("%lld%018lld\n", x.second, x.first);
  else
    printf("%lld\n", x.first);
}
void modify(int l, int r, int pos, int v, int cur) {
  if (l == r) {
    mn[cur] = v;
    return;
  }
  if (pos <= ((l + r) >> 1))
    modify(l, ((l + r) >> 1), pos, v, (cur << 1));
  else
    modify(((l + r) >> 1) + 1, r, pos, v, (cur << 1 | 1));
  mn[cur] = min(mn[(cur << 1)], mn[(cur << 1 | 1)]);
}
int query(int L, int R, int l, int r, int cur) {
  if (L <= l && R >= r) return mn[cur];
  int v = 2000000000;
  if (L <= ((l + r) >> 1))
    v = min(v, query(L, R, l, ((l + r) >> 1), (cur << 1)));
  if (R > ((l + r) >> 1))
    v = min(v, query(L, R, ((l + r) >> 1) + 1, r, (cur << 1 | 1)));
  return v;
}
void add(long long x, int v) { mp[x] += v, val += x * v; }
int update(int x) {
  int cnt = 0, top = 0;
  for (map<long long, int>::iterator it = mp.upper_bound(x); it != mp.end();
       ++it)
    st[++top] = it->first, cnt += it->second, val -= it->first * it->second;
  while (top) mp.erase(st[top--]);
  return cnt;
}
int main() {
  read(n), scanf("%s", c), s[1] = c[0] - 'a', read(w[1]);
  modify(1, n, 1, w[1], root), ans = ans + w[1], write(ans);
  for (int i = 2; i <= n; ++i) {
    scanf("%s", c), read(w[i]);
    s[i] = (c[0] - 'a' + ans % 26) % 26, w[i] ^= ans % (1 << 30);
    if (s[1] == s[i]) add(w[i], 1);
    modify(1, n, i, w[i], root), ans = ans + query(1, i, 1, n, root),
                                 pos = nxt[i - 1];
    while (pos && s[pos + 1] != s[i]) pos = nxt[pos];
    nxt[i] = pos + (s[pos + 1] == s[i]), col[i - 1] = s[i];
    for (int j = 0; j < 26; ++j) fa[i][j] = fa[nxt[i]][j];
    fa[i][col[nxt[i]]] = nxt[i];
    for (int c = 0; c < 26; ++c) {
      if (c == s[i]) continue;
      for (int j = fa[i - 1][c]; j; j = fa[j][c])
        add(query(i - j, i - 1, 1, n, root), -1);
    }
    add(w[i], update(w[i])), ans = ans + val, write(ans);
  }
  return 0;
}
