#include <bits/stdc++.h>
char S[1000001];
char T[1000001];
int nxt[2000000][22];
int calc(int v, int d) {
  int k = 0;
  while (d > 0) {
    if (d % 2 == 1 && v != -1) v = nxt[v][k];
    d /= 2;
    k++;
  }
  return v;
}
void solve(int n, int k, int d) {
  int i;
  int r = n - k + 1;
  for (i = 0; i < r; i++) nxt[i][0] = i - 1;
  int t = 0;
  for (i = 0; i < d; i++) {
    int p = i;
    while (p < k) {
      nxt[r + p][0] = r + t - 1;
      t++;
      p += d;
    }
  }
  for (i = r + k; i < r + n; i++) nxt[i][0] = i - 1;
  for (int j = 0; j < 21; j++) {
    for (i = 0; i < r + n; i++)
      if (nxt[i][j] != -1) nxt[i][j + 1] = nxt[nxt[i][j]][j];
  }
  for (i = 0; i < n; i++) T[calc(r + i, r)] = S[i];
  for (i = 0; i < n; i++) S[i] = T[i];
}
int main() {
  scanf(" %s", S);
  int n = strlen(S);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k, d;
    scanf("%d %d", &k, &d);
    solve(n, k, d);
    printf("%s\n", S);
  }
  return 0;
}
