#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int SQRTN = 320;
const int LOGN = 20;
const double PI = acos(-1);
const double Tau = 2 * acos(-1);
string s, s2;
int n, m;
vector<int> v, rot, r;
vector<int> mul(vector<int>& a, vector<int>& b) {
  vector<int> c(a.size());
  for (int i = 0; i < c.size(); i++) c[i] = a[b[i]];
  return c;
}
vector<int> fp(vector<int> a, int p) {
  if (p == 1) return a;
  vector<int> b = fp(a, p / 2);
  b = mul(b, b);
  if (p & 1) b = mul(b, a);
  return b;
}
int k, d, ctr;
int main() {
  cin >> s;
  cin >> m;
  n = s.size();
  for (int i = 0; i < n - 1; i++) rot.push_back(i + 1);
  rot.push_back(0);
  v.resize(n);
  r.resize(n);
  while (m--) {
    scanf("%d%d", &k, &d);
    for (int i = 0, ctr = 0; i < d; i++)
      for (int j = i; j < k; j += d) v[ctr++] = j;
    for (int i = k; i < n; i++) v[i] = i;
    v = fp(mul(v, rot), n - k + 1);
    for (int i = 0, ctr = 0; i < v.size(); i++)
      if (v[i] == 0)
        for (int j = i; j < i + n; j++) r[ctr++] = v[j % n];
    s2 = s;
    for (int i = 0; i < n; i++) s2[i] = s[r[i]];
    s = s2;
    printf("%s\n", s.c_str());
  }
  return 0;
}
