#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, q;
char a[2000000];
char b[2000000];
int p[22][2000000];
int main() {
  int i, j, k;
  scanf("%s%d", a, &q);
  n = strlen(a);
  for (; q; q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int now = 0;
    for (i = 0; i < y; i++) {
      for (j = i; j < x; j += y) {
        p[0][j] = now++;
      }
    }
    int cnt = n - x + 1;
    now = 0;
    for (i = 0; i < 21; i++) {
      if ((1 << i) > cnt) break;
      int nlen = x + ((1 << i) - 1);
      if (cnt & (1 << i)) {
        for (j = 0; j < nlen; j++) {
          b[p[i][j] + now] = a[j + now];
        }
        for (j = 0; j < nlen; j++) a[j + now] = b[j + now];
        now += (1 << i);
      }
      for (j = 0; j < nlen; j++) {
        p[i + 1][j] = (p[i][j] < (1 << i))
                          ? p[i][j]
                          : (p[i][p[i][j] - (1 << i)] + (1 << i));
      }
      for (j = nlen; j < nlen + (1 << i); j++) {
        p[i + 1][j] = p[i][j - (1 << i)] + (1 << i);
      }
    }
    printf("%s\n", a);
  }
  return 0;
}
