#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 6e5 + 10;
const int MASK = (1ll << 30) - 1;
const long long BASE = 1000000ll * 1000000ll * 1000000ll;
long long sum;
long long ans[2];
int ans26, ansMASK;
void add(long long x) {
  ans[0] += x;
  if (ans[0] >= BASE) ans[1]++, ans[0] -= BASE;
  ans26 = (ans26 + x) % 26;
  ansMASK = (ansMASK + x) & MASK;
}
void print() {
  if (ans[1])
    printf("%lld%018lld\n", ans[1], ans[0]);
  else
    printf("%lld\n", ans[0]);
}
int str[N], w[N], n;
int fail[N], anc[N];
map<int, int> mp;
int st[N], top;
void Erase(int x) {
  if (mp[x] == 1)
    mp.erase(mp.find(x));
  else
    mp[x]--;
  sum -= x;
}
int Q(int x) {
  int p = lower_bound(st + 1, st + top + 1, x) - st;
  return w[st[p]];
}
int main() {
  str[0] = -1;
  rd(n);
  int p = fail[0] = -1;
  for (int i = 1; i <= n; ++i) {
    char _s[10];
    scanf("%s%d", _s, &w[i]);
    str[i] = (_s[0] - 'a' + ans26) % 26;
    w[i] ^= ansMASK & MASK;
    if (i > 1) {
      if (str[fail[i - 1] + 1] == str[i])
        anc[i - 1] = anc[fail[i - 1]];
      else
        anc[i - 1] = fail[i - 1];
      for (int u = i - 1; u >= 1;)
        if (str[u + 1] == str[i])
          u = anc[u];
        else
          Erase(Q(i - 1 - u + 1)), u = fail[u];
    }
    while (~p && str[p + 1] != str[i]) p = fail[p];
    fail[i] = ++p;
    while (mp.size()) {
      map<int, int>::reverse_iterator it = mp.rbegin();
      if ((it->first) <= w[i]) break;
      sum += (long long)(it->second) * (w[i] - (it->first));
      mp[w[i]] += it->second;
      mp.erase(it->first);
    }
    if (str[1] == str[i]) mp[w[i]]++, sum += w[i];
    while (top && w[st[top]] >= w[i]) top--;
    st[++top] = i;
    add(sum);
    print();
  }
  return 0;
}
