#include <bits/stdc++.h>
using namespace std;
class Permutation {
  vector<int> p;

 public:
  Permutation(int n, int k, int d) {
    p = vector<int>(n);
    vector<int> x(n);
    for (int i = 0; i < n; ++i) x[i] = i;
    int val = 0;
    int nv = 1;
    for (int i = 0; i < k; ++i) {
      x[i] = val;
      val += d;
      if (val >= k) val = nv++;
    }
    for (int i = 0; i < n; ++i) p[x[i]] = i;
  }
  Permutation(int n) {
    p = vector<int>(n);
    for (int i = 0; i < n; ++i) p[(1 + i) % n] = i;
  }
  Permutation(vector<int>& vx) : p(vx) {}
  Permutation operator*(const Permutation& other) {
    vector<int> vx = vector<int>(p.size());
    for (int i = 0; i < p.size(); ++i) vx[i] = other.p[p[i]];
    return Permutation(vx);
  };
  string apply(string& s) {
    string res = s;
    for (int i = 0; i < p.size(); ++i) res[p[i]] = s[i];
    return res;
  }
};
Permutation pw(Permutation x, int deg) {
  if (deg == 1) return x;
  if (deg & 1) return x * pw(x, deg - 1);
  return pw(x * x, deg / 2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  char mem = s[0];
  s[0] = '@';
  int n = s.length();
  int m;
  cin >> m;
  string ans = "";
  while (m--) {
    int k, d;
    cin >> k >> d;
    Permutation cycl(n);
    Permutation dsort(n, k, d);
    Permutation res = dsort * cycl;
    res = pw(res, n - k + 1);
    s = res.apply(s);
    int ind = s.find('@');
    string y = s.substr(ind) + s.substr(0, ind);
    s = y;
    s[0] = mem;
    ans += s + '\n';
    s[0] = '@';
  }
  cout << ans;
}
