#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e6 + 7, maxL = 21;
char ch[maxN], str[maxN];
int n, m, k, d, top, t0[maxN], t1[maxN], trs[maxN];
void trans(int p) {
  if (p == 1) {
    for (int i = 0; i < n; i++) trs[i] = t0[i];
  } else {
    trans(p >> 1);
    for (int i = p >> 1; i < k + ((p >> 1) << 1) - 1; i++)
      t1[i] = trs[trs[i - (p >> 1)] + (p >> 1)];
    for (int i = p >> 1; i < k + ((p >> 1) << 1) - 1; i++) trs[i] = t1[i];
    if (p & 1) {
      for (int i = p - 1; i < n; i++) t1[i] = trs[t0[i - p + 1] + p - 1];
      for (int i = p - 1; i < n; i++) trs[i] = t1[i];
    }
  }
}
int main() {
  scanf("%s", str);
  n = strlen(str), scanf("%d", &m);
  for (int count = 0; count < m; count++) {
    scanf("%d%d", &k, &d);
    for (int p = 0, i = 0; i < d; i++)
      for (int t = i; t < k; t += d) t0[p++] = t;
    for (int i = k; i < n; i++) t0[i] = i;
    trans(n - k + 1);
    for (int i = 0; i < n; i++) ch[i] = str[trs[i]];
    for (int i = 0; i < n; i++) str[i] = ch[i];
    for (int i = 0; i < n; i++) printf("%c", str[i]);
    printf("\n");
  }
}
