#include <bits/stdc++.h>
using namespace std;
template <typename T>
void showArr(T *arr, int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << ' ';
  puts("");
}
const int MAXN = 1000007;
const int MOD = 1000000007;
char str[MAXN];
int x[MAXN];
int lm[MAXN], p[MAXN];
int buf[MAXN];
void filllm(int n) {
  for (int i = 0; i < n - 1; i++) lm[i] = i + 1;
  lm[n - 1] = 0;
}
void fillp(int n, int k, int d) {
  int top = 0;
  for (int i = 0; i < d; i++) {
    for (int j = i; j < k; j += d) p[top++] = j;
  }
  for (int j = k; j < n; j++) p[top++] = j;
}
void multp(int *a, int *b, int n) {
  for (int i = 0; i < n; i++) buf[i] = a[b[i]];
  for (int i = 0; i < n; i++) a[i] = buf[i];
}
int main() {
  while (~scanf("%s", str)) {
    int n = strlen(str);
    filllm(n);
    for (int i = 0; i < n; i++) x[i] = i;
    int q;
    scanf("%d", &q);
    while (q--) {
      int k, d;
      scanf("%d%d", &k, &d);
      fillp(n, k, d);
      multp(p, lm, n);
      int tm = n - k + 1;
      while (tm) {
        if (tm & 1) multp(x, p, n);
        multp(p, p, n);
        tm >>= 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++) putchar(str[x[i]]);
      puts("");
    }
  }
  return 0;
}
