#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000010;
char str[maxn], sans[maxn];
int dc[maxn], ans[maxn];
int len;
void makeCircleDSorting(int d, int k) {
  for (int initi = 0; initi < len; initi++) dc[initi] = initi;
  int idx = 0;
  for (int i = 0; i < d; i++) {
    for (int j = i; j < k; j += d) {
      dc[idx] = j;
      idx++;
    }
  }
  int tmp = dc[0];
  for (int i = 0; i < len; i++) {
    dc[i] = dc[i + 1];
  }
  dc[len - 1] = tmp;
}
int tmp[maxn];
void mutiMagic(int dc[], int times, int ans[]) {
  for (int initi = 0; initi < len; initi++) ans[initi] = initi;
  while (times) {
    if (times % 2 == 1) {
      for (int cm = 0; cm < len; cm++) tmp[cm] = ans[dc[cm]];
      for (int ci = 0; ci < len; ci++) ans[ci] = tmp[ci];
    }
    for (int cm = 0; cm < len; cm++) tmp[cm] = dc[dc[cm]];
    for (int ci = 0; ci < len; ci++) dc[ci] = tmp[ci];
    times /= 2;
  }
}
int main() {
  scanf("%s", str);
  len = strlen(str);
  int n, k, d;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &k, &d);
    if (d != 1) {
      makeCircleDSorting(d, k);
      int times = len - k + 1;
      mutiMagic(dc, times, ans);
      for (int j = 0; j < len; j++) {
        sans[j] = str[ans[(j + k - 1) % len]];
      }
      for (int ci = 0; ci < len; ci++) str[ci] = sans[ci];
    }
    printf("%s\n", str);
  }
}
