#include <bits/stdc++.h>
using namespace std;
vector<int> id;
vector<int> Zloz(vector<int>& a, vector<int>& b) {
  int n = a.size();
  vector<int> wyn(n);
  for (int i = 0; i < n; ++i) wyn[i] = a[b[i]];
  return wyn;
}
vector<int> Skladaj(vector<int>& p, int w) {
  if (w == 0) return id;
  if (w % 2 == 0) {
    vector<int> c;
    c = Skladaj(p, w / 2);
    return Zloz(c, c);
  }
  vector<int> c;
  c = Skladaj(p, w - 1);
  return Zloz(c, p);
}
int main() {
  char t[1000001];
  int m;
  scanf("%s %d", t, &m);
  int n = 0;
  while (t[n] != '\0') ++n;
  string s = "";
  for (int i = 0; i < n; ++i) s += t[i];
  for (int i = 0; i < n; ++i) id.push_back(i);
  for (int i = 0; i < m; ++i) {
    int k, d;
    scanf("%d %d", &k, &d);
    vector<int> p(n), q(n);
    int nr = 0;
    for (int j = 0; j < d; ++j) {
      for (int l = j; l < k; l += d) {
        p[l] = nr;
        ++nr;
      }
    }
    for (int j = k; j < n; ++j) p[j] = j;
    q[0] = n - 1;
    for (int j = 1; j < n; ++j) q[j] = j - 1;
    vector<int> qp;
    qp = Zloz(q, p);
    vector<int> wyn(n);
    wyn = Skladaj(qp, n - k + 1);
    string nowy = s;
    for (int j = 0; j < n; ++j) nowy[wyn[j]] = s[j];
    s = "";
    for (int j = k - 1; j < n; ++j) s += nowy[j];
    for (int j = 0; j < k - 1; ++j) s += nowy[j];
    for (int i = 0; i < n; ++i) printf("%c", s[i]);
    printf("\n");
  }
  return 0;
}
