#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T read() {
  T x = 0, w = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') w = -w;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * w;
}
template <class T>
inline T read(T& x) {
  return x = read<T>();
}
const int N = 6e5 + 10;
char s[N];
int w[N];
namespace ST {
int lg[N], mn[N][20];
void init(int n) {
  for (int i = 2; i <= n; ++i) lg[i] = lg[i >> 1] + 1;
}
void insert(int p, int v) {
  mn[p][0] = v;
  for (int i = 1; i <= lg[p]; ++i)
    mn[p][i] = min(mn[p][i - 1], mn[p - (1 << (i - 1))][i - 1]);
}
int query(int l, int r) {
  int k = lg[r - l + 1];
  return min(mn[r][k], mn[l + (1 << k) - 1][k]);
}
}  // namespace ST
namespace BT {
map<int, int> cnt;
long long sum;
void insert(int v, int c) {
  cnt[v] += c;
  sum += (long long)v * c;
}
int query(int v) {
  int siz = 0;
  vector<int> del;
  for (map<int, int>::iterator i = cnt.upper_bound(v); i != cnt.end(); ++i) {
    siz += i->second;
    del.push_back(i->first);
    sum -= (long long)i->first * i->second;
  }
  for (int x : del) cnt.erase(x);
  return siz;
}
}  // namespace BT
int nxt[N], col[N], fa[N][26];
const long long mod = 1e18;
inline int operator%(const pair<long long, long long>& x, int y) {
  return (x.first % y + (x.second % y) * (mod % y)) % y;
}
inline pair<long long, long long>& operator+=(pair<long long, long long>& x,
                                              long long y) {
  x.first += y, x.second += x.first / mod, x.first %= mod;
  return x;
}
inline void writeln(const pair<long long, long long> x) {
  if (x.second)
    printf("%lld%018lld\n", x.second, x.first);
  else
    printf("%lld\n", x.first);
}
int main() {
  int n = read<int>();
  ST::init(n);
  pair<long long, long long> ans = {0, 0};
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s + i), read(w[i]);
    s[i] = (s[i] - 'a' + ans % 26) % 26 + 'a', w[i] ^= ans % (1 << 30);
    ST::insert(i, w[i]);
    ans += ST::query(1, i);
    if (i == 1) {
      writeln(ans);
      continue;
    }
    int j = nxt[i - 1];
    while (j and s[j + 1] != s[i]) j = nxt[j];
    nxt[i] = j + (s[j + 1] == s[i]);
    col[i - 1] = s[i] - 'a';
    copy(fa[nxt[i]], fa[nxt[i]] + 26, fa[i]);
    fa[i][col[nxt[i]]] = nxt[i];
    if (s[1] == s[i]) BT::insert(w[i], 1);
    for (int c = 0; c < 26; ++c)
      if (c != s[i] - 'a')
        for (int j = fa[i - 1][c]; j; j = fa[j][c])
          BT::insert(ST::query(i - j, i - 1), -1);
    BT::insert(w[i], BT::query(w[i]));
    ans += BT::sum;
    writeln(ans);
  }
  return 0;
}
