#include <bits/stdc++.h>
using namespace std;
vector<int> operator*(vector<int> &c, vector<int> &d) {
  vector<int> ret(c.size());
  for (int i = 0; i < ret.size(); i++) ret[i] = c[d[i]];
  return ret;
}
vector<int> pow(vector<int> x, int y) {
  vector<int> ans(x.size());
  for (int i = 0; i < ans.size(); i++) ans[i] = i;
  while (y) {
    if (y & 1) ans = x * ans;
    x = x * x;
    y >>= 1;
  }
  return ans;
}
char s[1000005];
void print(vector<int> ob) {
  for (int i = 0; i < ob.size(); i++) printf("%d ", ob[i]);
  printf("\n");
}
int main() {
  vector<int> state;
  scanf("%s", s);
  int len = strlen(s);
  vector<int> shft_mat(len);
  for (int i = 0; i < len; i++) shft_mat[i] = (i + 1) % len;
  for (int i = 0; i < len; i++) state.push_back(i);
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int k, d;
    scanf("%d%d", &k, &d);
    vector<int> per;
    for (int rmdr = 0; rmdr < d; rmdr++)
      for (int q = 0; q * d + rmdr < k; q++) per.push_back(q * d + rmdr);
    for (int j = k; j < len; j++) per.push_back(j);
    vector<int> tm = per * shft_mat;
    vector<int> ans_mat = pow(tm, len - k + 1);
    vector<int> last_shft = pow(shft_mat, k - 1);
    ans_mat = ans_mat * last_shft;
    ans_mat = state * ans_mat;
    for (int i = 0; i < ans_mat.size(); i++) printf("%c", s[ans_mat[i]]);
    printf("\n");
    state = ans_mat;
  }
  return 0;
}
