#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e18;
template <typename T>
inline T read() {
  register T sum = 0;
  register char cc = getchar();
  int sym = 1;
  while (cc != '-' && (cc > '9' || cc < '0')) cc = getchar();
  if (cc == '-') sym = -1, cc = getchar();
  sum = sum * 10 + cc - '0';
  cc = getchar();
  while (cc >= '0' && cc <= '9') sum = sum * 10 + cc - '0', cc = getchar();
  return sym * sum;
}
template <typename T>
inline T read(T &a) {
  a = read<T>();
  return a;
}
template <typename T, typename... Others>
inline void read(T &a, Others &...b) {
  a = read(a);
  read(b...);
}
namespace ST {
int lg[600010], mn[600010][20];
void init(int n) {
  for (int i = 2; i <= n; i++) lg[i] = lg[i >> 1] + 1;
}
void insert(int x, int y) {
  mn[x][0] = y;
  for (int i = 1; i <= lg[x]; i++)
    mn[x][i] = min(mn[x][i - 1], mn[x - (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 Data {
map<int, int> mp;
long long sum;
void insert(int x, int y) {
  mp[x] += y;
  sum += 1ll * x * y;
}
int query(int x) {
  int tot = 0;
  for (auto i = mp.upper_bound(x); i != mp.end(); i = mp.erase(i)) {
    tot += i->second;
    sum -= 1ll * i->first * i->second;
  }
  return tot;
}
}  // namespace Data
int n, las, w[600010], fail[600010], go[600010][26];
char s[600010];
pair<long long, long long> ans;
int operator%(const pair<long long, long long> &x, int y) {
  return (x.second % y + (x.first % y) * (mod % y)) % y;
}
void operator+=(pair<long long, long long> &x, long long y) {
  x.second += y;
  x.first += x.second / mod;
  x.second %= mod;
}
void write(const pair<long long, long long> &x) {
  if (x.first)
    printf("%lld%018lld\n", x.first, x.second);
  else
    printf("%lld\n", x.second);
}
int main() {
  read(n);
  ST::init(n);
  for (int i = 1; i <= n; i++) {
    scanf(" %c", 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) {
      write(ans);
      continue;
    }
    while (las && s[las + 1] != s[i]) las = fail[las];
    las += s[las + 1] == s[i];
    fail[i] = las;
    copy(go[las], go[las] + 26, go[i]);
    go[i][s[las + 1] - 'a'] = las;
    if (s[1] == s[i]) Data::insert(w[i], 1);
    for (int j = 0; j < 26; j++)
      if (s[i] - 'a' != j)
        for (int k = go[i - 1][j]; k; k = go[k][j])
          Data::insert(ST::query(i - k, i - 1), -1);
    Data::insert(w[i], Data::query(w[i]));
    ans += Data::sum;
    write(ans);
  }
  return 0;
}
