#include <bits/stdc++.h>
using namespace std;
const int maxn = 600010;
int n, w[maxn], lnk[maxn], nxt[maxn], anc[maxn];
char s[maxn], c[2];
__int128 ans;
map<int, int> mp;
void print(__int128 ans) {
  if (ans > 9) print(ans / 10);
  putchar('0' + ans % 10);
}
int main() {
  scanf("%d %s %d", &n, c, &w[1]), s[1] = c[0];
  print(ans = w[1]), putchar('\n');
  long long inc = 0;
  vector<int> st = {1};
  for (int i = 2; i <= n; i++) {
    scanf("%s %d", c, &w[i]);
    s[i] = (c[0] - 'a' + ans % 26) % 26 + 'a';
    w[i] ^= (ans & ((1 << 30) - 1));
    int j = nxt[i - 1];
    anc[i - 1] = s[j + 1] == s[i] ? anc[j] : j;
    while (j && s[i] ^ s[j + 1]) j = nxt[j];
    if (s[i] == s[j + 1]) j++;
    nxt[i] = j;
    for (j = nxt[i - 1]; j;) {
      if (s[i] == s[j + 1]) {
        j = anc[j];
        continue;
      }
      int v = w[*lower_bound(st.begin(), st.end(), i - j)];
      inc -= v, j = nxt[j];
      if (!--mp[v]) mp.erase(v);
    }
    if (s[1] == s[i]) mp[w[i]]++, inc += w[i];
    while (!st.empty() && w[st.back()] >= w[i]) st.pop_back();
    st.push_back(i);
    while (!mp.empty() && mp.rbegin()->first > w[i]) {
      auto it = --mp.end();
      inc -= 1LL * (it->first - w[i]) * it->second;
      mp[w[i]] += it->second, mp.erase(it);
    }
    print(ans += inc + w[st[0]]), putchar('\n');
  }
  return 0;
}
