#include <bits/stdc++.h>
using namespace std;
const int inv = 1000000000;
const int minv = -inv;
const int max_n = 1000010;
char s[max_n + 5], t[max_n + 5];
int m, n;
int k, d;
int tmp[max_n];
void mul(int a[], int b[], int r[]) {
  for (int i = 0; i < n; ++i) tmp[i] = a[b[i]];
  for (int i = 0; i < n; ++i) r[i] = tmp[i];
}
void fexp(int a[], int p, int r[]) {
  if (p == 0) {
    for (int i = 0; i < n; ++i) r[i] = i;
  } else {
    fexp(a, p / 2, r);
    mul(r, r, r);
    if ((p & 1) == 1) mul(r, a, r);
  }
}
void print(int a[]) {
  for (int i = 0; i < n; ++i) printf("%d ", a[i]);
  printf("\n");
}
int dsort[max_n], shift[max_n], dsortshift[max_n];
int perm1[max_n], perm2[max_n], perm[max_n];
int dsortsz;
int main() {
  scanf("%s", s);
  for (n = 0; s[n] != 13 and s[n] != 0; ++n)
    ;
  s[n] = 0;
  scanf("%d", &m);
  for (int z = 0; z < m; ++z) {
    scanf("%d", &k);
    scanf("%d", &d);
    dsortsz = 0;
    for (int cbx = 0; cbx < d; ++cbx) {
      int cx = cbx;
      while (cx < k) {
        dsort[dsortsz++] = cx;
        cx += d;
      }
    }
    for (int i = k; i < n; ++i) dsort[dsortsz++] = i;
    for (int i = 0; i < n - 1; ++i) shift[i] = i + 1;
    shift[n - 1] = 0;
    mul(dsort, shift, dsortshift);
    fexp(dsortshift, n - k + 1, perm1);
    fexp(shift, k - 1, perm2);
    mul(perm1, perm2, perm);
    for (int i = 0; i < n; ++i) t[i] = s[perm[i]];
    for (int i = 0; i < n; ++i) s[i] = t[i];
    printf("%s\n", s);
  }
  return 0;
}
