#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, M = 26, mask = (1 << 30) - 1;
const long long p = 1e18;
int n, f[N], q[N], fa[N], siz[N], ch[N][M];
char s[N];
long long opt, w[N];
struct int128 {
  long long a, b;
  void inc(long long u) { b += u, a += b / p, b %= p; }
  void print() {
    if (!a)
      printf("%lld\n", b);
    else
      printf("%lld%018lld\n", a, b);
  }
} ans;
inline int read() {
  int num = 0;
  char g = getchar();
  while (g < 48 || 57 < g) g = getchar();
  while (47 < g && g < 58)
    num = (num << 1) + (num << 3) + g - 48, g = getchar();
  return num;
}
inline char get_char() {
  char g = getchar();
  while (g < 'a' || 'z' < g) g = getchar();
  return g;
}
inline int find(int u) {
  if (f[u] == u) return u;
  return f[u] = find(f[u]);
}
inline void merge(int u, int v) {
  u = find(u), v = find(v), opt = opt + (w[u] - w[v]) * siz[v],
  siz[u] += siz[v], f[v] = u;
}
inline void del(int u) {
  u = find(u);
  siz[u]--, opt -= w[u];
}
inline void build(int u) {
  fa[u] = ch[u - 1][s[u] - 'a'];
  ch[u - 1][s[u] - 'a'] = u;
  for (int z = 0; z < 26; z++) ch[u][z] = ch[fa[u]][z];
  if (!ch[u][s[1] - 'a']) ch[u][s[1] - 'a'] = 1;
}
int main() {
  n = read();
  s[1] = get_char(), w[1] = read(), ans.inc(w[1]), ans.print(), f[1] = 1,
  q[1] = 1, q[0] = 1, ch[1][s[1] - 'a'] = 1;
  for (int i = 2; i <= n; i++) {
    s[i] = (get_char() - 'a' + ans.b + (ans.a % 26) * (p % 26)) % 26 + 'a',
    w[i] = read() ^ (((ans.b & mask) + (ans.a & mask) * (p & mask)) & mask);
    f[i] = i;
    if (s[i] == s[1]) opt += w[i], siz[i] = 1;
    while (q[0] > 0 && w[q[q[0]]] > w[i]) merge(i, q[q[0]]), q[0]--;
    q[++q[0]] = i;
    build(i);
    for (int z = 0; z < 26; z++) {
      if (z == s[i] - 'a') continue;
      int c = ch[i - 1][z];
      while (c > 1) del(i - c + 1), c = fa[c];
    }
    ans.inc(w[q[1]]), ans.inc(opt);
    ans.print();
  }
  return 0;
}
