#include <bits/stdc++.h>
using namespace std;
char s[1000020], x[1000020];
int n, m, q, k, d, i, j, B;
int p[1000020], g[1000020], A[1000020];
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &m);
  while (m--) {
    q = 0;
    scanf("%d%d", &k, &d);
    for (i = 0; i < n; i++) p[i] = (i + 1) % n, A[i] = i;
    for (i = 0; i < d; i++)
      for (j = i; j < k; q++, j += d) p[(n - 1 + q) % n] = j;
    for (B = n - k + 1; B; B /= 2) {
      for (i = 0; i < n; g[i] = p[i], i++)
        if (B % 2) A[i] = p[A[i]];
      for (i = 0; i < n; i++) p[i] = g[p[i]];
    }
    for (i = 0; i < n; i++) x[(i + n - k + 1) % n] = s[A[i]];
    for (i = 0; i < n; i++) putchar(s[i] = x[i]);
    putchar('\n');
  }
}
