#include <bits/stdc++.h>
using namespace std;
const int maxnn = 1000000;
int maxn, fa[2 * maxnn + 10][20], sum[maxnn + 10], f[maxnn + 10], g[maxnn + 10];
char s[maxnn + 10], s2[maxnn + 10];
int kthfather(int x, int k) {
  int i = 0;
  x += maxn;
  while (k) {
    if (k & 1) x = fa[x][i];
    i++;
    k >>= 1;
  }
  return x;
}
int main() {
  scanf("%s", s);
  int l = strlen(s);
  maxn = l + 1;
  int m;
  scanf("%d", &m);
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    for (int i = 1; i <= maxn; i++) fa[i][0] = i - 1;
    sum[0] = 0;
    for (int i = 1; i < d; i++) sum[i] = sum[i - 1] + (k - i) / d + 1;
    for (int i = 0; i < k; i++) f[i] = sum[i % d] + i / d;
    for (int i = 1; i < k; i++) fa[i + maxn][0] = f[i] - 1 + maxn;
    for (int j = 1; j <= log(double(l)) / log(2.0); j++)
      for (int i = 1; i <= maxn + l; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
    for (int i = 0; i < k; i++)
      g[i] = kthfather(i, l - k + 1) - maxn + l - k + 1;
    for (int i = k; i < l; i++)
      g[i] = kthfather(k - 1, l - i) - maxn + l - k + 1;
    for (int i = 0; i < l; i++) s2[g[i]] = s[i];
    for (int i = 0; i < l; i++) putchar(s2[i]);
    putchar('\n');
    for (int i = 0; i < l; i++) s[i] = s2[i];
  }
  return 0;
}
