#include <bits/stdc++.h>
using namespace std;
const int maxn = int(1e6) + 10;
char ch[maxn];
int n, m, len, st;
int a[maxn], b[maxn], d[maxn], c[maxn];
int num[maxn], cir[maxn], total[maxn];
int vis[maxn];
vector<int> id[maxn];
char ans[maxn];
void Pow(int k) {
  for (int i = 0; i < len; i++) {
    int t = num[i], ct = total[cir[i]];
    int w = k % ct;
    w = (w + t) % ct;
    d[i] = id[cir[i]][w];
  }
}
int main() {
  scanf("%s", ch);
  len = strlen(ch);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &v, &u);
    int tot = 0, cnt = 0;
    for (int j = 0; j < len; j++) id[j].clear();
    for (int j = 0; j < u; j++) {
      int t = j;
      while (t < v) {
        a[tot++] = t;
        t += u;
      }
    }
    for (int j = v; j < len; j++) a[tot++] = j;
    for (int j = 0; j < len - 1; j++) c[j] = a[j + 1];
    c[len - 1] = a[0];
    for (int j = 0; j < len; j++) {
      if (vis[j] != i) {
        int td = 0, t = j;
        cnt++;
        while (vis[t] != i) {
          vis[t] = i;
          num[t] = td++;
          cir[t] = cnt;
          id[cnt].push_back(t);
          t = c[t];
        }
        total[cnt] = td;
      }
    }
    Pow(len - v + 1);
    st = 0;
    for (int j = 0; j < len; j++) ans[j] = ch[d[j]];
    for (int j = v - 1; j < len; j++) {
      ch[st++] = ans[j];
      printf("%c", ans[j]);
    }
    for (int j = 0; j < v - 1; j++) {
      ch[st++] = ans[j];
      printf("%c", ans[j]);
    }
    printf("\n");
  }
  return 0;
}
