#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e9;
long long powm(long long a, long long p, long long m) {
  long long r = 1 % m;
  while (p) {
    if (p & 1) r = r * a % m;
    p >>= 1;
    a = a * a % m;
  }
  return r;
}
char ss[1000001], tt[1000001];
char *s = ss, *t = tt;
vector<int> p(1000000), r(1000000), q(1000000);
int main() {
  int n, m, k, d;
  scanf("%s%d", s, &m);
  n = strlen(s);
  while (m--) {
    scanf("%d%d", &k, &d);
    for (int i = 0, j = 0; i < d; ++i)
      for (int t = i; t < k; t += d) p[j++] = t;
    for (int i = k; i < n; ++i) p[i] = i;
    for (int i = 0; i < (n - 1); ++i) p[i] = p[i + 1];
    p[n - 1] = 0;
    for (int i = 0; i < (n); ++i) r[i] = i;
    int w = n - k + 1;
    while (w) {
      if (w & 1) {
        for (int i = 0; i < (n); ++i) q[i] = r[p[i]];
        swap(r, q);
      }
      w /= 2;
      for (int i = 0; i < (n); ++i) q[i] = p[p[i]];
      swap(q, p);
    }
    for (int i = 0; i < (n); ++i) q[i] = r[(i + k - 1) % n];
    for (int i = 0; i < (n); ++i) t[i] = s[q[i]];
    swap(t, s);
    puts(s);
  }
  return 0;
}
