#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const long long B = (long long)1e9;
struct Num {
  vector<long long> a;
  Num() : a() {}
  Num(long long x) {
    a.clear();
    while (x > 0) {
      a.push_back(x % B);
      x /= B;
    }
  }
  Num operator+(const Num &A) const {
    Num R = Num();
    long long d = 0;
    for (int i = 0; i < (int)a.size() || i < (int)A.a.size() || d; i++) {
      if (i < (int)a.size()) d += a[i];
      if (i < (int)A.a.size()) d += A.a[i];
      R.a.push_back(d % B);
      d /= B;
    }
    return R;
  }
  void print() const {
    if (a.empty()) {
      printf("0\n");
      return;
    }
    printf("%lld", a.back());
    for (int i = (int)a.size() - 2; i >= 0; i--) printf("%09lld", a[i]);
    printf("\n");
  }
};
const int N = 600100;
int s[N];
int pi[N];
vector<int> needToErase[N];
int st[N][2];
int stSz;
long long globMin;
Num TOT = 0;
long long TOTm30 = 0;
long long TOTm26;
long long CUR = 0;
int n;
int fenv[N];
set<int> setik;
void addFenv(int p, int x) {
  for (; p < N; p |= p + 1) fenv[p] += x;
}
int getFenv(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += fenv[r];
  return res;
}
int getCost(int v) {
  int l = 0, r = stSz;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (st[mid][0] > v)
      r = mid;
    else
      l = mid;
  }
  return st[l][1];
}
void turnOff(int v) {
  CUR -= getCost(v);
  addFenv(v, -1);
  setik.erase(v);
}
void turnOn(int v) {
  CUR += getCost(v);
  addFenv(v, 1);
  setik.insert(v);
}
void solve(int p, int w) {
  42;
  int l = p;
  while (stSz > 0 && st[stSz - 1][1] >= w) {
    stSz--;
    CUR -= (long long)(getFenv(l - 1) - getFenv(st[stSz][0] - 1)) * st[stSz][1];
    l = st[stSz][0];
  }
  CUR += (long long)(getFenv(p) - getFenv(l - 1)) * w;
  st[stSz][0] = l;
  st[stSz][1] = w;
  stSz++;
  if (p == 0) {
    globMin = w;
    CUR = w;
    pi[0] = 0;
    return;
  }
  CUR -= globMin;
  globMin = min(globMin, (long long)w);
  CUR += globMin;
  pi[p] = pi[p - 1];
  while (pi[p] > 0 && s[p] != s[pi[p]]) pi[p] = pi[pi[p] - 1];
  if (pi[p] == 0) {
    while (!setik.empty()) {
      int v = *setik.begin();
      needToErase[p].push_back(p - v);
      turnOff(v);
    }
    if (s[p] == s[0]) {
      pi[p] = 1;
      turnOn(p);
    }
    return;
  }
  while (!setik.empty()) {
    int v = *setik.begin();
    if (v >= p - pi[p]) break;
    needToErase[p].push_back(p - v);
    turnOff(v);
  }
  for (int len : needToErase[pi[p]]) {
    needToErase[p].push_back(len);
    turnOff(p - len);
  }
  pi[p]++;
  if (s[p] == s[0]) {
    turnOn(p);
  }
}
void printAns() { TOT.print(); }
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    char c;
    int w;
    scanf(" %c %d", &c, &w);
    int cc = (int)(c - 'a');
    s[i] = (cc + TOTm26) % 26;
    w ^= TOTm30;
    solve(i, w);
    TOT = TOT + Num(CUR);
    TOTm30 = (TOTm30 + CUR) % (1LL << 30);
    TOTm26 = (TOTm26 + CUR) % 26;
    printAns();
  }
  return 0;
}
