#include <bits/stdc++.h>
using namespace std;
char s[1000000 + 10], a[1000000 + 10];
int ans[1000000 + 10], p[1000000 + 10], tmp[1000000 + 10];
int main(void) {
  scanf("%s", s);
  int n, m;
  n = strlen(s);
  scanf("%d", &m);
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    for (int i = 0; i < n; i++) {
      ans[i] = p[i] = i;
    }
    int cnt = 0;
    for (int x = 0; x < d; x++) {
      for (int j = x; j < k; j += d) {
        p[cnt++] = j;
      }
    }
    int last = p[0];
    for (int i = 0; i < n - 1; i++) {
      p[i] = p[i + 1];
    }
    p[n - 1] = last;
    int x = n - k + 1;
    while (x) {
      if (x & 1) {
        for (int j = 0; j < n; j++) {
          tmp[j] = ans[p[j]];
        }
        for (int j = 0; j < n; j++) {
          ans[j] = tmp[j];
        }
      }
      for (int j = 0; j < n; j++) {
        tmp[j] = p[p[j]];
      }
      for (int j = 0; j < n; j++) {
        p[j] = tmp[j];
      }
      x >>= 1;
    }
    for (int j = 0; j < n; j++) {
      a[j] = s[ans[(j + k - 1) % n]];
    }
    for (int j = 0; j < n; j++) {
      s[j] = a[j];
    }
    printf("%s\n", s);
  }
  return 0;
}
