#include <bits/stdc++.h>
using namespace std;
string x, y;
int a[1000006], t[1000006], h[1000006];
int w[1000006];
void ma(int z) {
  if (z == 1)
    for (int i = 1; i <= x.length(); i++) w[i] = h[h[i]];
  else
    for (int i = 1; i <= x.length(); i++) w[i] = h[a[i]];
  for (int i = 1; i <= x.length(); i++) h[i] = w[i];
}
void tran(int p) {
  if (p == 0) {
    for (int i = 1; i <= x.length(); i++) h[i] = i;
    return;
  }
  tran(p / 2);
  ma(1);
  if (p % 2) {
    ma(2);
  }
}
int main() {
  getline(cin, x);
  y = x;
  int m;
  scanf("%d", &m);
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    int cc = 0;
    for (int i = 1; i <= d; i++) {
      for (int j = i; j <= k; j += d) a[++cc] = j;
    }
    for (int i = k + 1; i <= x.length(); i++) a[i] = i;
    int tt = a[1];
    for (int i = 1; i <= x.length() - 1; i++) a[i] = a[i + 1];
    a[x.length()] = tt;
    tran(x.length() - k + 1);
    int r = x.length() - k + 1;
    for (int i = 1; i <= x.length(); i++) {
      if (i - r <= 0)
        a[i] = h[(i - r + x.length())];
      else
        a[i] = h[i - r];
    }
    for (int i = 1; i <= x.length(); i++) {
      y[i - 1] = x[a[i] - 1];
    }
    x = y;
    for (int i = 0; i <= x.length() - 1; i++) printf("%c", x[i]);
    printf("\n");
  }
  return 0;
}
