#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> mul(vector<int> a, vector<int> b) {
  for (int i = 0, n = a.size(); i < n; ++i) b[i] = a[b[i]];
  return b;
}
vector<int> bpow(vector<int> a, int p) {
  vector<int> r(a.size());
  iota(r.begin(), r.end(), 0);
  while (p > 0) {
    if (p & 1) {
      r = mul(a, r);
      --p;
    } else {
      a = mul(a, a);
      p >>= 1;
    }
  }
  return r;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size(), m;
  cin >> m;
  vector<int> q(n), p(n);
  iota(q.begin(), q.end(), 1);
  q.back() = 0;
  while (m--) {
    int k, d;
    cin >> k >> d;
    for (int i = 0, l = 0; i < d; i++)
      for (int j = i; j < k; j += d) p[l++] = j;
    for (int i = k; i < n; i++) p[i] = i;
    p = mul(p, q);
    p = bpow(p, n - k + 1);
    p = mul(p, bpow(q, k - 1));
    string t = "";
    for (int i = 0; i < n; i++) t += s[p[i]];
    cout << (s = t) << "\n";
  }
  return 0;
}
