#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000005;
const int mlog = 20;
int n, m, k, d;
int p[maxn], par[maxn][mlog];
char s[maxn], ns[maxn];
int qry(int x, int y, int s) {
  for (int i = mlog - 1; i >= 0; i--)
    if (par[x][i] >= 0 && y >= (1 << i))
      s += (1 << i), y -= (1 << i), x = par[x][i];
  return s + x;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &k, &d);
    int c = 0;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) p[c++] = j;
    for (int i = 0; i < k; i++) par[p[i]][0] = i - 1;
    for (int j = 1; j < mlog; j++)
      for (int i = 0; i < k; i++) {
        if (par[i][j - 1] < 0)
          par[i][j] = -1;
        else
          par[i][j] = par[par[i][j - 1]][j - 1];
      }
    for (int i = 0; i < n; i++)
      ns[qry(min(i, k - 1), n - k - max(0, i - k + 1) + 1, max(0, i - k + 1))] =
          s[i];
    for (int i = 0; i < n; i++) s[i] = ns[i], putchar(s[i]);
    putchar('\n');
  }
  return 0;
}
