#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
char s[N];
int n, m, k, d;
int Left[N], Sort[N], All[N], Cur[N], tt[N];
int main() {
  scanf("%s", s);
  n = strlen(s);
  for (int i = 1; i < n; i++) Left[i] = i - 1;
  Left[0] = n - 1;
  scanf("%d", &m);
  for (int ii = 1; ii <= m; ii++) {
    scanf("%d%d", &k, &d);
    for (int i = 0; i < n; i++) Sort[i] = i;
    int tot = 0;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) Sort[j] = tot++;
    for (int i = 0; i < n; i++) Cur[i] = Sort[i];
    for (int i = 0; i < n; i++) All[i] = Sort[Left[i]];
    int Times = n - k;
    while (Times) {
      if (Times & 1) {
        for (int i = 0; i < n; i++) Cur[i] = All[Cur[i]];
      }
      for (int i = 0; i < n; i++) tt[i] = All[All[i]];
      for (int i = 0; i < n; i++) All[i] = tt[i];
      Times >>= 1;
    }
    for (int i = 0; i < n; i++) tt[Cur[i]] = s[i];
    for (int i = 0; i < n; i++) s[(i + (n - k)) % n] = tt[i];
    printf("%s\n", s);
  }
  return 0;
}
