#include <bits/stdc++.h>
using namespace std;
int N, M, D, P[1000005], G[1000005], Ans[1000005];
char s[1000005], t[1000005];
int main() {
  scanf("%s%d", s, &M);
  N = strlen(s);
  for (int k, d; M--; puts(""), D = 0) {
    scanf("%d%d", &k, &d);
    for (int i = 0; i < N; i++) P[i] = Ans[i] = i;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) P[D++] = j;
    P[N] = P[0];
    for (int i = 0; i < N; i++) P[i] = P[i + 1];
    for (int t = N - k + 1; t; t >>= 1) {
      if (t & 1)
        for (int i = 0; i < N; i++) Ans[i] = P[Ans[i]];
      for (int i = 0; i < N; i++) G[i] = P[i];
      for (int i = 0; i < N; i++) P[i] = G[P[i]];
    }
    for (int i = 0; i < N; i++) t[(i + N - k + 1) % N] = s[Ans[i]];
    for (int i = 0; i < N; i++) printf("%c", s[i] = t[i]);
  }
}
