#include <bits/stdc++.h>
using namespace std;
char s[1100000], t[1100000];
int n, m, an, a[1100000], b[1100000], c[1100000], k, d;
void find(int m) {
  int i, j = m % 2, _m = m;
  if (m == 1) {
    for (i = 0; i < n; i++) b[i] = a[i];
    return;
  }
  find(m / 2);
  m /= 2;
  int en = 2 * m + k - 1;
  for (i = 0; i < m; i++) c[i] = b[i];
  for (i = m; i < en; i++) c[i] = b[m + b[i - m]];
  for (; i < n; i++) c[i] = b[i];
  if (j) {
    m = _m - 1;
    for (i = 0; i < m; i++) b[i] = c[i];
    for (i = m; i < m + k; i++) b[i] = c[m + a[i - m]];
    for (; i < n; i++) b[i] = c[i];
  } else {
    for (i = 0; i < n; i++) b[i] = c[i];
  }
}
void operate() {
  int i, j;
  for (an = i = 0; i < d; i++)
    for (j = i; j < k; j += d) a[an++] = j;
  for (i = k; i < n; i++) a[i] = i;
  find(n - k + 1);
  for (i = 0; i < n; i++) t[i] = s[b[i]];
  for (i = 0; i < n; i++) s[i] = t[i];
}
int main() {
  scanf("%s%d", s, &m);
  n = strlen(s);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &k, &d);
    operate();
    printf("%s\n", s);
  }
}
