#include <bits/stdc++.h>
const int MAX = 1000005;
int next[20][MAX], p[MAX], tmp[MAX];
char s[MAX], t[MAX];
int main() {
  scanf("%s", s);
  int n = strlen(s), q;
  scanf("%d", &q);
  while (q--) {
    int k, d;
    scanf("%d %d", &k, &d);
    int cnt = 0;
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) p[j] = cnt++;
    for (int i = 0; i < n; i++) next[0][i] = (p[i] - 1 + n) % n;
    for (int i = 1; i < 20; i++)
      for (int j = 0; j < n; j++) next[i][j] = next[i - 1][next[i - 1][j]];
    for (int i = 0; i < n; i++) p[i] = i;
    for (int i = 0; i < 20; i++)
      if ((1 << i) & (n - k + 1)) {
        for (int j = 0; j < n; j++) tmp[j] = next[i][p[j]];
        for (int j = 0; j < n; j++) p[j] = tmp[j];
      }
    for (int i = 0; i < n; i++) t[p[i]] = s[i];
    for (int i = 0; i < n; i++) s[i] = t[(i + k - 1) % n];
    printf("%s\n", s);
  }
  return 0;
}
