#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long infLL = 0x3f3f3f3f3f3f3f3fLL;
const int maxn = 1000000 + 5;
vector<int> multiply(const vector<int> &p1, const vector<int> &p2) {
  vector<int> res(p1.size());
  for (int i = 0; i < res.size(); ++i) res[i] = p1[p2[i]];
  return res;
}
vector<int> pow(vector<int> a, long long b) {
  vector<int> res(a.size());
  for (int i = 0; i < res.size(); ++i) res[i] = i;
  for (; b; a = multiply(a, a), b >>= 1)
    if (b & 1) res = multiply(res, a);
  return res;
}
int n, m, d, k;
char s[maxn];
vector<int> S, P, C;
int main() {
  scanf("%s%d", s, &m);
  n = strlen(s);
  S.resize(n);
  P.resize(n);
  C.resize(n);
  for (int i = 0; i < (n); ++i) S[i] = i, C[i] = (i + 1) % n;
  while (m--) {
    scanf("%d%d", &k, &d);
    int now = 0;
    for (int i = 0; i < d; ++i)
      for (int j = i; j < k; j += d) P[now++] = j;
    for (int i = k; i < n; ++i) P[i] = i;
    S = multiply(S, multiply(pow(multiply(P, C), n - k + 1), pow(C, k - 1)));
    for (int i = 0; i < (n); ++i) putchar(s[S[i]]);
    puts("");
  }
  return 0;
}
