#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 600005;
const long long P = 1e18;
int q[N], Q[N], nxt[N], S, top;
char ch[N];
unsigned long long sum, ans;
long long a, b;
map<int, int> M;
char s[3];
vector<int> v[N];
int ask(int pos) { return Q[lower_bound(q + 1, q + top + 1, pos) - q]; }
int main() {
  int n = read();
  for (int i = (int)(0); i <= (int)(n - 1); i++) {
    scanf("%s", s);
    ch[i] = (s[0] - 'a' + S) % 26 + 'a';
    int w = read() ^ (ans & ((1 << 30) - 1));
    nxt[i] = i ? nxt[i - 1] : 0;
    if (i) {
      while (ch[nxt[i]] != ch[i] && nxt[i]) {
        v[i].push_back(nxt[i]);
        nxt[i] = nxt[nxt[i] - 1];
      }
      if (ch[nxt[i]] == ch[i]) {
        for (auto j : v[nxt[i]]) v[i].push_back(j);
        nxt[i]++;
      }
      for (auto j : v[i]) {
        int t = ask(i - j);
        M[t]--;
        sum -= t;
      }
    }
    if (ch[0] == ch[i]) {
      M[w]++;
      sum += w;
    }
    if (i) {
      M[w] += 0;
      auto it = M.find(w), j = it;
      for (j++; j != M.end(); M.erase(j++)) {
        sum -= ((long long)j->first - w) * j->second;
        it->second += j->second;
      }
    }
    while (top && Q[top] >= w) top--;
    q[++top] = i;
    Q[top] = w;
    ans += sum;
    S = (S + sum) % 26;
    b += sum;
    if (b >= P) {
      a++;
      b -= P;
    }
    if (a) {
      write(a);
      for (long long j = P / 10; j > 1; j /= 10)
        if (b < j) putchar('0');
      writeln(b);
    } else
      writeln(b);
  }
}
