#include <bits/stdc++.h>   using namespace std;   const int maxn = 1e6 + 5;   char s[maxn], t[maxn];   int p[maxn], q[maxn], r[maxn];   int main() {     int n, m, k, d;     scanf( %s%d , s, &m);     n = strlen(s);     while (m--) {       scanf( %d%d , &k, &d);       for (int i = 0; i < n; i++) p[i] = q[i] = i;       int id = 0;       for (int i = 0; i < d; i++) {         for (int j = i; j < k; j += d) p[id++] = j;       }       int last = p[0];       for (int i = 0; i < n - 1; i++) p[i] = p[i + 1];       p[n - 1] = last;       int pw = n - k + 1;       while (pw > 0) {         if (pw & 1) {           for (int i = 0; i < n; i++) r[i] = q[p[i]];           for (int i = 0; i < n; i++) q[i] = r[i];         }         for (int i = 0; i < n; i++) r[i] = p[p[i]];         for (int i = 0; i < n; i++) p[i] = r[i];         pw >>= 1;       }       for (int i = 0; i < n; i++) t[i] = s[q[(k + i - 1) % n]];       for (int i = 0; i < n; i++) s[i] = t[i];       puts(s);     }     return 0;   }   