#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e6 + 10;
;
string str, strt;
int num[maxn], n, r[maxn], c[maxn], s[maxn], res[maxn], m, tmp[maxn];
void mul() {
  for (int i = 0; i < n; i++) tmp[i] = s[s[i]];
  for (int i = 0; i < n; i++) s[i] = tmp[i];
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> str;
  strt = str;
  n = str.size();
  cin >> m;
  while (m--) {
    int k, d, cnt = 0;
    cin >> k >> d;
    for (int i = 0; i < n; i++) res[i] = c[i] = i;
    for (int i = 0; i < d; i++) {
      for (int j = i; j < k; j += d) c[cnt++] = j;
    }
    for (int i = 0; i < n; i++) r[i] = (i + 1) % n;
    for (int i = 0; i < n; i++) s[i] = c[r[i]];
    for (int i = 0; i < 30; i++) {
      if ((n - k + 1) & (1 << i)) {
        for (int j = 0; j < n; j++) res[j] = s[res[j]];
      }
      mul();
    }
    for (int i = 0; i < n; i++) tmp[i] = res[(i + k - 1) % n];
    for (int i = 0; i < n; i++) strt[i] = str[tmp[i]];
    str = strt;
    for (int i = 0; i < n; i++) printf("%c", str[i]);
    printf("\n");
  }
}
