#include <bits/stdc++.h>
using namespace std;
const int N = 1000000 + 10;
const int LOG = 20;
const int MOD = 1e9 + 7;
int n, m;
int k, d;
char s[N];
char ns[N];
int to[N][LOG];
int calcIt(int p, int step) {
  int cnt = 0;
  for (int i = 0; step; step >>= 1, ++i) {
    if (step & 1) {
      if (p < cnt) return p;
      p = to[p - cnt][i] + cnt;
      cnt += (1 << i);
    }
  }
  return p;
}
void solveIt() {
  int tot = 0;
  for (int i = 0; i < d; ++i) {
    for (int j = i; j < k; j += d) {
      to[j][0] = tot++;
    }
  }
  for (int i = 1; i < LOG; ++i) {
    for (int j = 0; j < k; ++j) {
      if (to[j][i - 1] < (1 << (i - 1))) {
        to[j][i] = to[j][i - 1];
      } else {
        int nPos = to[j][i - 1] - (1 << (i - 1));
        to[j][i] = to[nPos][i - 1] + (1 << (i - 1));
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    int st, step, in;
    if (i < k) {
      st = i;
      in = 0;
    } else {
      st = k - 1;
      in = i - k + 1;
    }
    step = n - k - in + 1;
    int nPos = calcIt(st, step);
    ns[nPos - st + i] = s[i];
  }
  for (int i = 0; i < n; ++i) {
    s[i] = ns[i];
  }
}
void solve() {
  scanf("%s", s);
  n = strlen(s);
  cin >> m;
  for (int i = 0; i < m; ++i) {
    scanf("%d%d", &k, &d);
    solveIt();
    puts(s);
  }
}
int main() {
  solve();
  return 0;
}
