#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
int p[maxn], L[maxn], R[maxn], res[maxn];
int n, tmp[maxn];
char s[maxn], str[maxn];
void mul(int *a, int *b) {
  for (int i = 0; i < n; i++) tmp[i] = b[a[i]];
  for (int i = 0; i < n; i++) a[i] = tmp[i];
}
void qpow(int *a, int y) {
  for (int i = 0; i < n; i++) res[i] = i;
  while (y) {
    if (y & 1) mul(res, a);
    mul(a, a);
    y /= 2;
  }
  for (int i = 0; i < n; i++) a[i] = res[i];
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  int m, k, d;
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &k, &d);
    int cnt = 0;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) p[cnt++] = j;
    for (int i = k; i < n; i++) p[i] = i;
    for (int i = 0; i < n; i++) L[i] = p[(i + 1) % n], R[i] = (i + k) % n;
    qpow(L, n - k);
    mul(p, L);
    mul(R, p);
    for (int i = 0; i < n; i++) printf("%c", str[i] = s[R[i]]);
    strcpy(s, str);
    puts("");
  }
}
