#include <bits/stdc++.h>
using namespace std;
namespace BIT {
int sumv[600005];
void add(int x, int n, int num) {
  for (; x <= n; x += (x & -x)) sumv[x] += num;
}
int sum(int x) {
  int s = 0;
  for (; x; x -= (x & -x)) s += sumv[x];
  return s;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
}  // namespace BIT
char str[600005];
int fail[600005], ed[600005];
int fa[600005], len[600005], cur[600005];
int num[600005], st[600005];
void output(__int128 x) {
  if (!x) putchar('0');
  char str[30];
  int cnt = 0;
  for (; x; x /= 10) str[++cnt] = x % 10;
  for (; cnt; cnt--) putchar(str[cnt] + '0');
}
int main() {
  int n;
  scanf("%d", &n);
  int top = 0, sz = 0;
  long long s = 0;
  __int128 ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%s%d", str + i, &num[i]);
    str[i] = 'a' + (str[i] - 'a' + ans) % 26;
    num[i] ^= (ans & ((1 << 30) - 1));
    int cnt = 0, x = fail[i - 1];
    while (x && str[x + 1] != str[i]) {
      cur[++cnt] = x;
      x = fail[x];
    }
    if (i > 1 && str[x + 1] == str[i]) x++;
    fail[i] = x;
    ed[i] = ed[x];
    for (int j = cnt; j > 0; j--) {
      len[++sz] = cur[j];
      fa[sz] = ed[i];
      ed[i] = sz;
    }
    for (int j = ed[i]; j; j = fa[j]) {
      int u = i - len[j], t = st[lower_bound(st + 1, st + top + 1, u) - st];
      BIT::add(u, n, -1);
      s -= num[t];
    }
    while (top && num[st[top]] >= num[i]) {
      s -= (long long)(num[st[top]] - num[i]) *
           BIT::sum(st[top - 1] + 1, st[top]);
      top--;
    }
    st[++top] = i;
    if (str[i] == str[1]) {
      BIT::add(i, n, 1);
      s += num[i];
    }
    ans += s;
    output(ans);
    printf("\n");
  }
  return 0;
}
