#include <bits/stdc++.h>
using namespace std;
int from[1000001];
int base[1000001];
int nxt[1000001];
char S[1000001];
char res[1000001];
int main() {
  scanf("%s", S);
  int len = strlen(S);
  res[len] = 0;
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k, d;
    scanf("%d %d", &k, &d);
    int idx = 0;
    for (int i = 0; i < d; i++)
      for (int now = i; now < k; now += d) from[idx++] = now + 1;
    for (int i = k; i < len; i++) from[i] = i + 1;
    from[len] = len;
    int pos = 1;
    for (int i = 0; i <= len - k; i++) {
      res[i] = S[pos - 1];
      pos = from[pos];
    }
    int iter = len - k + 1;
    for (int i = 0; i <= len; i++) base[i] = i;
    for (int bit = 20; bit >= 0; bit--) {
      for (int i = 0; i <= len; i++) nxt[i] = base[base[i]];
      if (iter & (1 << bit)) {
        for (int i = 0; i <= len; i++) base[i] = nxt[from[i]];
      } else {
        for (int i = 0; i <= len; i++) base[i] = nxt[i];
      }
    }
    for (int i = 1; i < k; i++) {
      res[len - k + i] = S[base[i] - 1];
    }
    printf("%s\n", res);
    for (int i = 0; i < len; i++) S[i] = res[i];
  }
}
