#include <bits/stdc++.h>
using namespace std;
const long long K = 1000000000000000000;
map<int, int> M;
int q, mn, w[600005], nxt[600005], Q[600005], anc[600005], r;
char opt[5], s[600005];
long long ans0, ans, g, ansx, ansy;
int mask((1 << 30) - 1);
int calc(int x) { return w[Q[lower_bound(Q + 1, Q + r + 1, x) - Q]]; }
int main() {
  mn = 1 << 30;
  scanf("%d", &q);
  int j(0);
  for (int i = 1; i <= q; ++i) {
    scanf("%s%d", opt, &w[i]);
    s[i] = (ansy + opt[0] - 'a') % 26 + 'a';
    w[i] ^= (ansx & mask);
    mn = min(mn, w[i]);
    if (i == 1) {
      printf("%lld\n", ans = w[i]);
      ansx = ans & mask;
      ansy = w[i] % 26;
      while (r && w[Q[r]] >= w[i]) --r;
      Q[++r] = i;
      continue;
    }
    while (j && s[j + 1] != s[i]) j = nxt[j];
    if (s[j + 1] == s[i]) ++j;
    nxt[i] = j;
    if (s[i] == s[nxt[i - 1] + 1])
      anc[i - 1] = anc[nxt[i - 1]];
    else
      anc[i - 1] = nxt[i - 1];
    for (int j = (s[i - 1] == s[1] ? i - 1 : nxt[i - 1]); j;) {
      if (s[j + 1] == s[i])
        j = anc[j];
      else {
        int o(calc(i - j));
        g -= o;
        map<int, int>::iterator it = M.lower_bound(o);
        assert(it != M.end());
        --it->second;
        if (!it->second) M.erase(it);
        j = nxt[j];
      }
    }
    while (r && w[Q[r]] >= w[i]) --r;
    Q[++r] = i;
    int cnt(s[i] == s[1]);
    map<int, int>::iterator it = M.lower_bound(w[i]);
    while (it != M.end()) {
      g -= (long long)it->first * it->second;
      cnt += it->second;
      M.erase(it);
      it = M.lower_bound(w[i]);
    }
    g += (long long)cnt * w[i];
    M.insert(make_pair(w[i], cnt));
    ans += g, ans += mn;
    if (ans >= K) ++ans0, ans -= K;
    ansx = (ansx + g + mn) & mask;
    ansy = (ansy + g + mn) % 26;
    if (!ans0)
      printf("%lld\n", ans);
    else {
      cout << ans0 << setw(18) << setfill('0') << ans << endl;
    }
  }
  return 0;
}
