#include <bits/stdc++.h>   using namespace std;   const int N = 1000008;   int n, m, k, d, i, j, e;   int tmp[N], pos[N], p[N], c[N];   char s[N];   int main() {     scanf( %s %d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (i = 0; i < n; i++) {         c[i] = (i + 1) % n;         pos[i] = p[i] = i;       }       int t = 0;       for (i = 0; i < d; i++)         for (j = i; j < k; t++, j += d) p[t] = j;       for (i = 0; i < n; ++i) {         c[i] = p[c[i]];       }       for (e = n - k + 1; e; e >>= 1) {         for (i = 0; i < n; ++i) tmp[i] = c[i];         if (e & 1)           for (i = 0; i < n; ++i) pos[i] = c[pos[i]];         for (i = 0; i < n; ++i) c[i] = tmp[c[i]];       }       for (i = 0; i < n; ++i) tmp[(i + n - k + 1) % n] = s[pos[i]];       for (i = 0; i < n; ++i) putchar(s[i] = (char)tmp[i]);       putchar(  n );     }   }   