#include <bits/stdc++.h>
using namespace std;
int n;
string s, ans;
int m;
int d, k;
vector<int> mult(const vector<int> &a, const vector<int> &b) {
  vector<int> c(n);
  for (int i = 0; i < n; i++) c[i] = b[a[i]];
  return c;
}
vector<int> pow(const vector<int> &a, const int &b) {
  if (b == 1)
    return a;
  else {
    vector<int> ret = pow(mult(a, a), b / 2);
    if (b & 1) ret = mult(ret, a);
    return ret;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s;
  n = s.length();
  ans.resize(n);
  cin >> m;
  while (m--) {
    cin >> k >> d;
    vector<int> dper(n);
    for (int i = 0, indx = 0; i < d; i++)
      for (int j = i; j < k; j += d) dper[j] = indx++;
    for (int i = k; i < n; i++) dper[i] = i;
    vector<int> sper(n);
    for (int i = 0; i < n; i++) sper[i] = (i - 1 + n) % n;
    vector<int> per = pow(mult(dper, sper), n - k + 1);
    for (int i = 0; i < n; i++) ans[(per[i] + (n - k + 1)) % n] = s[i];
    s = ans;
    cout << ans << "\n";
  }
  return 0;
}
