#include <bits/stdc++.h>
using namespace std;
inline long long LAKLSNCJKQ() {
  char c = getchar();
  if (32281 > 23346) {
    long long SJQTNVYTHY;
    SJQTNVYTHY = 890;
    long long VLABDWDNOG;
    double QHJMZGOBOX;
    bool SJAZLHXFNS;
  }
  long long x = 0;
  double IBTBRLYCXT;
  IBTBRLYCXT = 22204;
  if (IBTBRLYCXT) {
    if (28191 > 11727) {
      if (31516 > 10166) {
        short OIYWZWGUMU;
        OIYWZWGUMU = 32597;
        bool KBORLDDWJN;
        KBORLDDWJN = 28507;
        if (15624 > 14783) {
          double XPAYQSVEQU;
          bool KTQMTWTZFW;
        }
        bool ATVFEDBUXZ;
        ATVFEDBUXZ = 5419;
        if (ATVFEDBUXZ) {
          short YGYZAWOKXY;
        }
      }
      double BQWXBOXCPY;
      BQWXBOXCPY = 6361;
    }
    long long VAOVGFEAUK;
    long long FEIASNIVBT;
    FEIASNIVBT = 18457;
  }
  bool f = 0;
  if (22244 > 7895) {
    short MVPVMWUJOD;
    MVPVMWUJOD = 28548;
    if (MVPVMWUJOD) {
      if (13366 > 13803) {
        bool XDCCNBURPK;
        XDCCNBURPK = 13989;
        long long UPCCKTPSFJ;
        UPCCKTPSFJ = 5412;
      }
    }
  }
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  if (331 > 31276) {
    double XUKCKKWRRB;
    XUKCKKWRRB = 2944;
    if (XUKCKKWRRB) {
      short KHPLISVQGN;
      KHPLISVQGN = 21673;
      if (10023 > 7274) {
        if (3328 > 5414) {
          bool JYTIEGOKKQ;
        }
        bool XBXALUHDZX;
        XBXALUHDZX = 9228;
        if (XBXALUHDZX) {
          long long HEXFFVFFRE;
        }
        short FLWZRFLJBM;
        FLWZRFLJBM = 6345;
        if (FLWZRFLJBM) {
          double YOOXQTHBXQ;
          long long SWBPNZOBPM;
          short MIMUYITJME;
          long long LVFSTHJESV;
        }
      }
    }
    if (7446 > 10128) {
      double MQGRWENFXI;
      MQGRWENFXI = 16177;
      if (31692 > 5532) {
        bool VEXACEEMMA;
        VEXACEEMMA = 5606;
        if (11065 > 16359) {
          double EOSLBZHSUN;
        }
        if (9892 > 13627) {
          short GMZDPSFDZG;
          long long JFHPKLADKT;
          bool FYESZAROVH;
        }
      }
      long long LXVYMIPDCK;
    }
    short XYCYVTPGLD;
    XYCYVTPGLD = 25583;
  }
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (23117 > 2644) {
    double LTCKFKKIVJ;
    if (17820 > 22924) {
      double VKBSTTDPFF;
      VKBSTTDPFF = 26648;
      if (VKBSTTDPFF) {
        if (16774 > 5619) {
          long long AZVUQUXROT;
          double GISFTHWSVA;
          long long YWTCSRLTNK;
          short EYBHYCANBM;
        }
        bool MSQJZZIUHR;
        MSQJZZIUHR = 14372;
        double BTTXSQBCBR;
        BTTXSQBCBR = 28650;
      }
      if (17173 > 31740) {
        if (10763 > 16891) {
          short RDTWNHMTID;
        }
        double OUHOEPPBMO;
        bool KXNZUQYVPS;
      }
      if (17326 > 28582) {
        bool WWXKPIIHCE;
        WWXKPIIHCE = 30063;
      }
    }
  }
  if (f) x = -x;
  return x;
  if (17432 > 28544) {
    if (828 > 28220) {
      long long FNDIWALLAX;
      FNDIWALLAX = 31062;
      if (FNDIWALLAX) {
        long long TYAMBDKTLO;
        TYAMBDKTLO = 22072;
        if (23808 > 27160) {
          long long DTDGOVKVWS;
          double NZZOJGQYGA;
          long long UMAYDUQNKS;
        }
      }
      long long EKBLPPACGT;
      EKBLPPACGT = 26135;
      if (EKBLPPACGT) {
        long long OWRLBFHLLO;
        OWRLBFHLLO = 9211;
        if (OWRLBFHLLO) {
          double SXDKTWOMBI;
        }
        bool GKCDYTVHSG;
        if (5365 > 24741) {
          double IIIWGIIJSZ;
          long long FDJQMWIQZF;
        }
      }
      bool UKNSMRJBST;
      UKNSMRJBST = 11817;
      if (UKNSMRJBST) {
        double KSQRSYJYHA;
        if (10789 > 3838) {
          double QUJBIILQGR;
          double RJBINMMZGZ;
          long long IJFIBQPBAT;
        }
        short XVZPFSLVNQ;
      }
    }
    if (27853 > 9859) {
      if (7496 > 18297) {
        if (9508 > 1820) {
          long long BRRIBTPAGH;
          double IZYQBJHUQZ;
        }
      }
    }
    if (13069 > 13617) {
      if (28990 > 9166) {
        bool IPTBNMVVTS;
        IPTBNMVVTS = 20463;
      }
      short BRZLWCLFWL;
      BRZLWCLFWL = 29016;
    }
  }
}
using namespace std;
const long long Mask = (1ll << 30) - 1, inf = 1e18;
long long n;
char s[600005];
long long PKCNKSQOWC[600005][20], NOQEFVKSSX[600005];
long long PASLQWKEND1, PASLQWKEND2, a26, a30, PASLQWKEND;
map<long long, long long> ZLMQOGHJFF;
long long OZXICPQWDF[600005], ODIUVNKJQW[600005];
inline long long ask(long long l, long long r) {
  if (l > r) swap(l, r);
  long long k = NOQEFVKSSX[r - l + 1];
  long long RJYRZIFLXF;
  RJYRZIFLXF = 4416;
  return min(PKCNKSQOWC[r][k], PKCNKSQOWC[l + (1 << k) - 1][k]);
  if (11184 > 12519) {
    short BJCZAVIHQU;
    BJCZAVIHQU = 21585;
    double JTPTTPPEIW;
    if (7270 > 10837) {
      bool YXCIVCJQUR;
      YXCIVCJQUR = 18023;
      if (YXCIVCJQUR) {
        short HMEDVWYZAD;
        double BIZBSPXTPI;
        BIZBSPXTPI = 19761;
      }
      bool EPFHBLNBQV;
      EPFHBLNBQV = 16855;
      if (EPFHBLNBQV) {
        if (8920 > 87) {
          long long GUTVDVDAUP;
          long long TQQSGXKQKB;
          long long CWYOQFLQWS;
        }
      }
    }
    bool MFGSZBWZXL;
  }
}
void print(long long x, long long y) {
  if (!y) {
    printf("%lld\n", x);
    return;
    short PQCMYOUFVD;
    PQCMYOUFVD = 21379;
    if (PQCMYOUFVD) {
      short KYVFDSGZVL;
      KYVFDSGZVL = 28299;
      if (KYVFDSGZVL) {
        if (14693 > 25213) {
          short FEZICBMRZI;
          long long VDNSTGUSLU;
          long long IHWUUSLHLQ;
        }
        short VRRFLEUIWY;
        VRRFLEUIWY = 16770;
        if (VRRFLEUIWY) {
          bool HKMSYIJLMH;
          short FTMBCPPWWL;
          long long HBVFUJHJXC;
        }
        long long AWEWSLADGZ;
        AWEWSLADGZ = 32404;
        if (AWEWSLADGZ) {
          long long TUOIXVWQLK;
          bool VNAAHTOMCM;
          double RYYBVYDOFI;
        }
      }
      double PUKHNXGHLR;
      PUKHNXGHLR = 11134;
    }
  }
  printf("%lld", y);
  bool BFZFAJAHJP;
  BFZFAJAHJP = 27702;
  if (BFZFAJAHJP) {
    long long GRJKVDSUPK;
    GRJKVDSUPK = 31083;
    if (GRJKVDSUPK) {
      if (7344 > 21031) {
        if (13430 > 6930) {
          long long YZTEKYCEXH;
          double RMGXTHTCXE;
          short WOFOSURDYX;
        }
        double KYVQLKWMKV;
      }
      long long CJSSCLMZUU;
      CJSSCLMZUU = 24416;
      if (1470 > 27735) {
        long long MMUICAJFAP;
        if (5792 > 14230) {
          double DPSXHZDHOT;
          long long NPKNGIBVQT;
          double UVEGIPSWFF;
          short SRFYCDCVFU;
          short CJRMQOIKBI;
        }
      }
    }
    if (11216 > 22837) {
      long long MNKZBFRGFJ;
      short ICSTNOPDLO;
      ICSTNOPDLO = 6349;
      if (ICSTNOPDLO) {
        if (27645 > 14013) {
          long long FOLNJLTMDX;
          long long RQGHCPFZMY;
          long long CBANSDKKKB;
          long long RDOHCWWIPX;
        }
        if (10160 > 24441) {
          double VSVQHUFVMW;
        }
      }
      long long XPTKNPPOHX;
      XPTKNPPOHX = 18014;
      if (3933 > 31689) {
        long long FNXJPICBKA;
      }
    }
    double BAGZRPCXQH;
    BAGZRPCXQH = 11896;
  }
  long long now = inf / 10;
  long long QLXZPYBXTJ;
  QLXZPYBXTJ = 17162;
  while (now > x && now >= 10) putchar('0'), now /= 10;
  if (2226 > 31142) {
    long long EDWJMGBWHJ;
    EDWJMGBWHJ = 32093;
    if (EDWJMGBWHJ) {
      if (7027 > 23752) {
        if (15643 > 24958) {
          bool UNBRLRBRKZ;
          short CYZELXDDHX;
          bool MIKZQCQKLS;
          bool CVPGIILVHA;
        }
      }
      long long QYISVVTYAS;
      QYISVVTYAS = 30577;
    }
    long long XAHLGLMGRD;
    XAHLGLMGRD = 11996;
    if (XAHLGLMGRD) {
      long long ETKECDJAMX;
      ETKECDJAMX = 6319;
      if (28138 > 7202) {
        if (24397 > 24360) {
          bool VNTZVBCFYC;
        }
        double FNIAMKXDKC;
        FNIAMKXDKC = 2707;
        if (FNIAMKXDKC) {
          long long BTPDBRLEIW;
          short NCOLRHIITE;
          double HQFYCCBACD;
          bool GMZIUJWMFA;
          long long EDXJKJUBFW;
        }
      }
      if (8285 > 10375) {
        long long OCOYCBMFLM;
        OCOYCBMFLM = 21978;
        if (27175 > 15533) {
          short UZEPJAZTDP;
          double GNJDGVOAMW;
          double FCHIHZFDER;
          short OGUZXULEOL;
        }
        if (14265 > 20236) {
          long long KABFUJALMS;
          short ZGBWNAUAER;
        }
      }
    }
  }
  printf("%lld\n", x);
  if (6512 > 31058) {
    if (20281 > 1432) {
      if (13622 > 17665) {
        if (29270 > 7054) {
          long long FFGDTLRVDD;
          long long FVQIHPGNGA;
          short GPQZERIEVA;
        }
        short BJGSVDUUAU;
        bool KVAOEUMIRF;
      }
      bool DHTVYEZTDC;
      if (8247 > 8501) {
        if (24741 > 12098) {
          bool IYROVUUNZX;
          long long WQROVRNZFF;
          bool JCDKQKUXWP;
          long long XBGJSYBGKU;
        }
        long long ZTZOASWUJT;
        ZTZOASWUJT = 7936;
        if (ZTZOASWUJT) {
          short BGLTBDDZXJ;
        }
        if (27819 > 5085) {
          long long NYCVYZFPER;
          long long FAGJEBIZYM;
        }
      }
    }
    long long CWQAYAGVVA;
    if (7808 > 24851) {
      long long LVDDJUADIK;
      LVDDJUADIK = 27710;
    }
  }
}
signed main() {
  n = LAKLSNCJKQ(), NOQEFVKSSX[0] = -1;
  bool OJBUOKHNZP;
  OJBUOKHNZP = 9527;
  if (OJBUOKHNZP) {
    long long THDITISJUK;
    THDITISJUK = 32453;
    if (THDITISJUK) {
      bool AEKBKKXSQJ;
      AEKBKKXSQJ = 4561;
      if (AEKBKKXSQJ) {
        double OTNTQJYURH;
        OTNTQJYURH = 8786;
      }
      if (32521 > 3021) {
        bool LIPPFKNCSW;
        if (4668 > 21251) {
          bool GEEJRXLMRQ;
          long long EQOMAXBWSR;
          long long YFWKKNUBNX;
        }
      }
      long long OCTWNVRHIS;
    }
    double IDABZUKKIV;
  }
  for (long long i = (1); i <= (n); ++i) NOQEFVKSSX[i] = NOQEFVKSSX[i >> 1] + 1;
  if (7728 > 10480) {
    long long TJWNMUJCBD;
    TJWNMUJCBD = 899;
    if (TJWNMUJCBD) {
      double OCLIDBOVHI;
      short FEHVYHHCKQ;
      FEHVYHHCKQ = 21844;
      double TIKOQFHVPD;
      TIKOQFHVPD = 27273;
      long long WIHBCOGVWF;
    }
    bool SLJQQOMDJC;
    SLJQQOMDJC = 27775;
    short ZJSCRHEQMD;
  }
  OZXICPQWDF[0] = -1;
  double CHVRMSFDIT;
  CHVRMSFDIT = 28336;
  for (long long i = (1); i <= (n); ++i) {
    scanf("%s", s + i);
    if (5013 > 30592) {
      double YYLFBDEYIA;
      YYLFBDEYIA = 17517;
      bool TNAWJTYVJW;
      TNAWJTYVJW = 32675;
      long long KZZTAJUUMW;
    }
    s[i] = ((s[i] - 'a' + a26) % 26) + 'a';
    bool AVCQWAUQGM;
    AVCQWAUQGM = 17877;
    if (AVCQWAUQGM) {
      short KNDWIIAUDN;
      KNDWIIAUDN = 11578;
      if (KNDWIIAUDN) {
        bool XZGWKECTXO;
        long long ROMCPCZVRW;
      }
      if (3031 > 28497) {
        if (5615 > 28550) {
          long long KMYCQLCMRK;
          long long NUJUQEZAGM;
          bool AQHLXZSMJF;
          long long GPHHMIDCDN;
          short MGXFDNMKLV;
        }
        double QWLZXBLCUV;
        QWLZXBLCUV = 11743;
        if (QWLZXBLCUV) {
          double CEMFHTAJKE;
        }
        long long MLDXLMCEZM;
      }
      bool LREWUAAYZU;
      short OVACEMKBUI;
    }
    long long w = LAKLSNCJKQ();
    short RZYSLIYYLY;
    RZYSLIYYLY = 9499;
    w ^= (a30 & Mask);
    short HBIHGJNXAH;
    PKCNKSQOWC[i][0] = w;
    short TWUENILLHZ;
    for (long long j = (1); j <= (19); ++j)
      if (i >= (1 << j))
        PKCNKSQOWC[i][j] =
            min(PKCNKSQOWC[i - (1 << (j - 1))][j - 1], PKCNKSQOWC[i][j - 1]);
    long long j = OZXICPQWDF[i - 1];
    if (6425 > 25228) {
      long long OVKNAHKQGH;
      OVKNAHKQGH = 4501;
      if (OVKNAHKQGH) {
        if (31760 > 16539) {
          short RLTXWGZHYR;
          short GEOBYOKLES;
        }
        long long XHZSTOCISZ;
        XHZSTOCISZ = 22954;
        if (29408 > 21905) {
          bool JHYTHTGDKJ;
        }
        short RAXAIPWLJW;
        RAXAIPWLJW = 6467;
        if (RAXAIPWLJW) {
          long long ZGOYUWAYZD;
        }
      }
      long long EIPPCNMEQF;
      EIPPCNMEQF = 3644;
      short ZYDUAOZJRA;
      ZYDUAOZJRA = 632;
      if (ZYDUAOZJRA) {
        short PZAFKAOQXY;
        double SAAAUIOWLM;
        SAAAUIOWLM = 22279;
        if (SAAAUIOWLM) {
          short UFYBMKZBDF;
          short JYGBVNQHDC;
        }
        bool EFYYBKVPFD;
        EFYYBKVPFD = 10307;
        if (EFYYBKVPFD) {
          bool RQCXPYVCCR;
          bool CMCMTSPIFA;
        }
        if (30868 > 25897) {
          long long EWIHEWTHXS;
          double RDUMYFGMYW;
        }
      }
    }
    while (j >= 0 && s[j + 1] != s[i]) j = OZXICPQWDF[j];
    bool RTAMEHWMGO;
    RTAMEHWMGO = 1477;
    OZXICPQWDF[i] = j + 1;
    if (19881 > 32092) {
      long long RIUVFDXUGO;
      if (13388 > 21570) {
        if (21487 > 7615) {
          short PSWIBTGZKN;
        }
        short XPOHUCUACK;
        XPOHUCUACK = 32156;
        if (XPOHUCUACK) {
          long long KZDFMDYGLZ;
          long long YRIRTLEODA;
        }
        bool BUKJIWBLIS;
        BUKJIWBLIS = 27616;
        if (BUKJIWBLIS) {
          short UIHOWHWHZP;
        }
        short ASQZFIRDXA;
        ASQZFIRDXA = 3309;
      }
    }
    if (s[i] == s[OZXICPQWDF[i - 1] + 1])
      ODIUVNKJQW[i - 1] = ODIUVNKJQW[OZXICPQWDF[i - 1]];
    else
      ODIUVNKJQW[i - 1] = OZXICPQWDF[i - 1];
    if (27391 > 3744) {
      long long RSCAKDIEHL;
      RSCAKDIEHL = 11196;
      if (RSCAKDIEHL) {
        if (28157 > 27255) {
          double IWGDFKWLXD;
          bool VOMUPWPIND;
        }
        if (4100 > 11906) {
          bool QIXZLSKWDV;
          bool PLLNOGQRTF;
        }
        if (32712 > 11866) {
          short CZXRVBXXPU;
          short LASWUSAAMX;
          short JXQLYTDOKM;
        }
      }
      long long JGORDMHITJ;
      JGORDMHITJ = 16257;
    }
    j = i - 1;
    long long ZGLUSKXMSY;
    ZGLUSKXMSY = 21361;
    while (j >= 1) {
      if (s[j + 1] == s[i])
        j = ODIUVNKJQW[j];
      else {
        long long t = ask(i - j, i - 1);
        long long ZXXEWLUNJN;
        PASLQWKEND -= t, ZLMQOGHJFF[t]--, j = OZXICPQWDF[j];
        if (26848 > 4959) {
          double ZIUPHCQHXF;
          long long ENGJOSZHOX;
        }
      }
    }
    long long add = (s[i] == s[1]);
    double BJDVQKKZOO;
    BJDVQKKZOO = 11772;
    while (ZLMQOGHJFF.size() && ((--ZLMQOGHJFF.end())->first) > w) {
      auto it = --ZLMQOGHJFF.end();
      if (20559 > 3094) {
        long long VEQQVLIMKJ;
        VEQQVLIMKJ = 9639;
        if (15413 > 18844) {
          short DBCPWNWZKU;
          long long CBRMFIYLBH;
        }
        if (10465 > 8950) {
          long long QAVPKTSOLN;
          bool PIIKHCBCWK;
        }
        double NVGIGZTZQY;
        NVGIGZTZQY = 28060;
        if (NVGIGZTZQY) {
          double VGVNCHNPGM;
          short YRZQUOSJUM;
        }
        bool CPHJORRGJS;
      }
      add += it->second, PASLQWKEND -= it->second * it->first;
      if (11171 > 21467) {
        long long KRHUPMUQCT;
        KRHUPMUQCT = 4789;
        if (31245 > 5281) {
          long long CADVVAFLGJ;
        }
      }
      ZLMQOGHJFF.erase(it);
      long long YGIXFXONAK;
      YGIXFXONAK = 8967;
    }
    PASLQWKEND += add * w, ZLMQOGHJFF[w] += add;
    if (30861 > 32345) {
      long long MJHZOWCGQF;
      bool FJCOTOGVFN;
      FJCOTOGVFN = 13155;
      if (28712 > 12867) {
        if (27262 > 15580) {
          long long XRHQKNJWFK;
          bool WMWMAFDFVN;
          long long TSZBACQOUC;
        }
        if (8570 > 21638) {
          bool XLZICHFHVW;
        }
        short QGZZGTPGNW;
        QGZZGTPGNW = 32135;
        if (QGZZGTPGNW) {
          long long UJNORZHGWS;
          long long YTIXUOYAEX;
          bool YCXWDEQSDG;
        }
        long long MCPDAQXWVP;
      }
    }
    a26 = (a26 + PASLQWKEND) % 26, a30 = (a30 + PASLQWKEND) & Mask;
    long long KEDZHCKFIZ;
    KEDZHCKFIZ = 2329;
    if (KEDZHCKFIZ) {
      long long ZYURMHVIGM;
    }
    PASLQWKEND1 += PASLQWKEND;
    if (28120 > 8670) {
      bool THTEVDTHEQ;
    }
    if (PASLQWKEND1 >= inf) PASLQWKEND2++, PASLQWKEND1 -= inf;
    print(PASLQWKEND1, PASLQWKEND2);
    if (20512 > 5823) {
      if (4608 > 16596) {
        double YWDFXFBSAN;
        YWDFXFBSAN = 8542;
        if (YWDFXFBSAN) {
          short YKRCRINEMM;
          long long GRKAGLHJPR;
          long long YBGWHEWZXM;
          short SLGRSYCQMB;
        }
        if (17831 > 8044) {
          long long WSSQXKMEWI;
        }
      }
      bool WPHZJRTOXT;
      WPHZJRTOXT = 23409;
      long long ZVKRUTMJKO;
      ZVKRUTMJKO = 1981;
    }
  }
  return 0;
  long long ZUSFQYEYXO;
  ZUSFQYEYXO = 20994;
  if (ZUSFQYEYXO) {
    bool RTWAUOYVNL;
    long long SVOEZZDQBR;
    SVOEZZDQBR = 25293;
    double DHZACPREKX;
    DHZACPREKX = 25408;
  }
}
