#include <bits/stdc++.h>
const int NMAX = 1000 * 1005;
void fillP(const int& n, const int& d, const int& k, int P[]) {
  int top = 0;
  for (int i = 0; i < d; ++i) {
    int cur = i;
    while (cur < k) {
      P[top++] = cur;
      cur += d;
    }
  }
  for (int i = k; i < n; ++i) P[top++] = i;
}
void fillC(const int& n, int C[]) {
  for (int i = 1; i < n; ++i) C[i - 1] = i;
  C[n - 1] = 0;
}
int buf[NMAX];
void multiply(int X[], int tmp[], const int& n) {
  for (int i = 0; i < n; ++i) buf[i] = X[tmp[i]];
  for (int i = 0; i < n; ++i) X[i] = buf[i];
}
char S[NMAX];
int X[NMAX], P[NMAX], C[NMAX];
int main() {
  int m;
  scanf("%s%d", S, &m);
  const int n = strlen(S);
  fillC(n, C);
  for (int i = 0; i < n; ++i) X[i] = i;
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    fillP(n, d, k, P);
    multiply(P, C, n);
    int pw = n - k + 1;
    while (pw) {
      if (pw & 1) multiply(X, P, n);
      multiply(P, P, n);
      pw >>= 1;
    }
    for (int i = 0; i < n; ++i) buf[i] = X[(i + k - 1) % n];
    for (int i = 0; i < n; ++i) X[i] = buf[i];
    for (int i = 0; i < n; ++i) printf("%c", S[X[i]]);
    printf("\n");
  }
  return 0;
}
