#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6;
char s[maxn + 5];
int n, k, d, l;
int c[maxn + 1], cw[maxn + 1], a[maxn + 1];
void get1(int k, int d, int *c) {
  int tt = 0;
  for (int i = 1; i <= d; i++) {
    for (int j = i; j <= k; j += d) c[++tt] = j;
  }
  assert(tt == k);
  for (int i = k + 1; i <= l; i++) c[i] = i;
}
void get2(int *c) {
  for (int i = 1; i <= l - 1; i++) c[i] = i + 1;
  c[l] = 1;
}
void get3(int *c) {
  for (int i = 1; i <= l; i++) c[i] = i;
}
void mul(int *a, int *b) {
  for (int i = 1; i <= l; i++) a[i] = b[a[i]];
}
int ti[maxn + 1];
void mul2(int *a, int *b) {
  for (int i = 1; i <= l; i++) ti[i] = b[a[i]];
  for (int i = 1; i <= l; i++) b[i] = ti[i];
}
void pt(int *a) {
  for (int i = 1; i <= l; i++) printf("%d ", a[i]);
  printf("\n");
}
void getpow(int *a, int *b, int p) {
  while (p) {
    if (p & 1) {
      mul(a, b);
    }
    mul2(b, b);
    p >>= 1;
  }
}
void work(int k, int d) {
  get1(k, d, c);
  get2(cw);
  get3(a);
  mul(cw, c);
  getpow(a, cw, l - k + 1);
  int j = 0;
  for (int i = k; i <= l; i++) putchar(ti[++j] = s[a[i]]);
  for (int i = 1; i <= k - 1; i++) putchar(ti[++j] = s[a[i]]);
  putchar('\n');
  for (int i = 1; i <= l; i++) s[i] = ti[i];
}
int main() {
  scanf("%s\n", s);
  l = strlen(s);
  for (int i = l; i > 0; i--) s[i] = s[i - 1];
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &k, &d);
    work(k, d);
  }
  return 0;
}
