#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("avx2,tune=native")
using namespace std;
vector<int> mult(vector<int> a, vector<int> b) {
  vector<int> c((int)a.size());
  for (int i = 0; i < (int)a.size(); i++) c[i] = b[a[i]];
  return c;
}
vector<int> binpow(vector<int> base, int st) {
  vector<int> res((int)base.size());
  iota(res.begin(), res.end(), 0);
  while (st) {
    if (st & 1) res = mult(base, res);
    base = mult(base, base);
    st >>= 1;
  }
  return res;
}
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s;
  int q;
  vector<int> ds((int)s.size()), sd;
  sd.resize((int)s.size());
  iota(sd.begin(), sd.end(), 1);
  sd[sd.size() - 1] = 0;
  cin >> q;
  while (q--) {
    int k, d;
    cin >> k >> d;
    int l = 0;
    for (int i = 0; i < d; i++)
      for (int j = i; j < k; j += d) ds[l++] = j;
    for (int i = k; i < (int)s.size(); i++) ds[l++] = i;
    int cnt = (int)s.size() - k + 1;
    vector<int> res = mult(sd, ds);
    res = binpow(res, (int)s.size() - k + 1);
    res = mult(binpow(sd, (int)s.size() - cnt), res);
    string t;
    for (auto u : res) t += s[u];
    cout << (s = t) << "\n";
  }
  return 0;
}
