#include <bits/stdc++.h>
using namespace std;
int z[1000010];
void vector_mul(int *x, int *y, int n) {
  for (int i = 0; i < n; i++) z[i] = x[y[i]];
  for (int i = 0; i < n; i++) x[i] = z[i];
}
int t[1000010];
void vector_pow(int *x, int n, int k) {
  for (int i = 0; i < n; i++) t[i] = i;
  while (k) {
    if (k & 1) vector_mul(t, x, n);
    vector_mul(x, x, n);
    k >>= 1;
  }
  for (int i = 0; i < n; i++) x[i] = t[i];
}
char q[1000010];
char s[1000010];
int l_move[1000010];
int d_sort[1000010];
int main(int argc, char *argv[]) {
  int n, m, k, d;
  scanf("%s", q);
  n = strlen(q);
  for (int i = 0; i < n; i++) l_move[i] = (i + 1) % n;
  cin >> m;
  while (m--) {
    scanf("%d%d", &k, &d);
    int x = 0;
    int y = 0;
    for (int i = 0; i < n; i++) d_sort[i] = i;
    for (int i = 0; i < k; i++) {
      d_sort[i] = x + y * d;
      if (x + (y + 1) * d >= k) {
        x += 1;
        y = 0;
      } else {
        y += 1;
      }
    }
    vector_mul(d_sort, l_move, n);
    vector_pow(d_sort, n, n - k + 1);
    for (int i = 0; i < n; i++) {
      s[i] = q[d_sort[i]];
    }
    x = 0;
    for (int i = k - 1; i < n; i++) q[x++] = s[i];
    for (int i = 0; i < k - 1; i++) q[x++] = s[i];
    printf("%s\n", q);
  }
  return 0;
}
