#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long r;
  while (b != 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int maxn = 1000010;
int n, m;
char s[maxn];
int p[maxn];
int tmp[2][maxn];
char ans[maxn];
void solve() {
  memset(ans, 0, sizeof(ans));
  scanf("%s", s);
  n = strlen(s);
  for (int i = (0); i < (n); i++) p[i] = i;
  scanf("%d", &m);
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    bool cnt = 0;
    int l = 0;
    for (int i = (0); i < (d); i++)
      for (int j = i; j < k; j += d) tmp[cnt][j] = (n - 1 + l++) % n;
    for (int i = (k); i < (n); i++) tmp[cnt][i] = (i + n - 1) % n;
    for (int i = (0); i < (n); i++) p[i] = tmp[cnt][p[i]];
    int c = n - k;
    while (c) {
      if (c & 1)
        for (int i = (0); i < (n); i++) p[i] = tmp[cnt][p[i]];
      for (int i = (0); i < (n); i++) tmp[cnt ^ 1][i] = tmp[cnt][tmp[cnt][i]];
      c >>= 1;
      cnt ^= 1;
    }
    for (int i = (0); i < (n); i++) {
      p[i] = (p[i] + n - k + 1) % n;
      ans[p[i]] = s[i];
    }
    printf("%s\n", ans);
  }
}
int main() {
  solve();
  return 0;
}
