#include <bits/stdc++.h>
const int MAXN = 1000006;
int n, m, k, d;
char s[MAXN], s1[MAXN];
int cur[MAXN], res[MAXN], c[MAXN];
void mul(int *a, int *b) {
  for (int i = 1; i <= n; i++) c[i] = a[b[i]];
  for (int i = 1; i <= n; i++) a[i] = c[i];
}
int main() {
  scanf("%s %d", s + 1, &m);
  n = strlen(s + 1);
  while (m--) {
    int cnt = 0;
    scanf("%d %d", &k, &d);
    for (int i = 1; i <= d; i++)
      for (int h = i; h <= k; h += d) cur[++cnt] = h;
    for (int i = k + 1; i <= n; i++) cur[i] = i;
    cur[n + 1] = cur[1];
    for (int i = 1; i <= n; i++) cur[i] = cur[i + 1], res[i] = i;
    cnt = n - k + 1;
    while (cnt) {
      if (cnt & 1) mul(res, cur);
      mul(cur, cur), cnt >>= 1;
    }
    for (int i = k; i <= n; i++) s1[i - k + 1] = s[res[i]];
    for (int i = 1; i < k; i++) s1[i + n - k + 1] = s[res[i]];
    for (int i = 1; i <= n; i++) s[i] = s1[i];
    printf("%s\n", s + 1);
  }
}
