#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
int ans[N], mul[N], tmp[N];
char str[N], tm_[N];
int main() {
  scanf("%s", str);
  int n = strlen(str);
  int m;
  cin >> m;
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    int tot = 0;
    for (int i = 0; i <= d - 1; i++)
      for (int j = i; j < k; j += d) mul[tot++] = j;
    for (int i = k; i <= n - 1; i++) mul[i] = i;
    for (int i = 0; i <= n - 1; i++) tmp[i] = mul[(i + 1) % n];
    for (int i = 0; i <= n - 1; i++) mul[i] = tmp[i];
    for (int i = 0; i <= n - 1; i++) ans[i] = i;
    int val = n - k + 1;
    for (; val; val >>= 1) {
      if (val & 1) {
        for (int i = 0; i <= n - 1; i++) tmp[i] = ans[mul[i]];
        for (int i = 0; i <= n - 1; i++) ans[i] = tmp[i];
      }
      for (int i = 0; i <= n - 1; i++) tmp[i] = mul[mul[i]];
      for (int i = 0; i <= n - 1; i++) mul[i] = tmp[i];
    }
    for (int i = 0; i <= n - 1; i++) tmp[i] = ans[(i + k - 1) % n];
    for (int i = 0; i <= n - 1; i++) ans[i] = tmp[i];
    for (int i = 0; i <= n - 1; i++) tm_[i] = str[ans[i]];
    for (int i = 0; i <= n - 1; i++) str[i] = tm_[i];
    puts(str);
  }
  return 0;
}
