#include <bits/stdc++.h>
using namespace std;
char s[1000006];
struct permutation {
  int sz;
  vector<int> p, temp;
  permutation() {}
  permutation(int n) {
    sz = n;
    p.resize(n);
    temp.resize(n);
  }
  void shift_left(int n) {
    for (int i = n, j = 0; i < sz; i++, j++) {
      temp[j] = p[i];
    }
    for (int i = 0, j = sz - n; i < n; i++, j++) {
      temp[j] = p[i];
    }
    for (int i = 0; i < sz; i++) {
      p[i] = temp[i];
    }
  }
  void shift_right(int n) {
    for (int i = 0, j = n; i < sz - n; i++, j++) {
      temp[j] = p[i];
    }
    for (int i = sz - n, j = 0; j < n; i++, j++) {
      temp[j] = p[i];
    }
    for (int i = 0; i < sz; i++) {
      p[i] = temp[i];
    }
  }
  void print() {
    for (int i = 0; i < sz; i++) {
      cout << p[i] << " ";
    }
    cout << endl;
  }
};
permutation P, A;
void precal(int n) {
  P = permutation(n);
  A = permutation(n);
  for (int i = 0; i < n; i++) {
    P.p[i] = i;
  }
}
permutation multiply(const permutation &a, const permutation &b) {
  permutation res(a.sz);
  for (int i = 0; i < a.sz; i++) {
    res.p[i] = a.p[b.p[i]];
  }
  return res;
}
permutation fast_power(permutation &a, int b) {
  permutation res(a.sz);
  for (int i = 0; i < a.sz; i++) {
    res.p[i] = i;
  }
  while (b) {
    if (b & 1) {
      res = multiply(res, a);
    }
    a = multiply(a, a);
    b >>= 1;
  }
  return res;
}
void d_sorting(int n, int d, int k) {
  int idx = 0;
  for (int i = 0; i < d; i++) {
    for (int j = i; j < k; j += d) {
      A.p[idx++] = j;
    }
  }
  for (int i = k; i < n; i++) {
    A.p[idx++] = i;
  }
  A.shift_left(1);
  A = fast_power(A, n - k + 1);
  P = multiply(P, A);
  P.shift_right(n - k + 1);
}
int main() {
  int m;
  int d, k;
  int n;
  scanf("%s", s);
  scanf("%d", &m);
  n = strlen(s);
  precal(n);
  while (m--) {
    scanf("%d%d", &k, &d);
    d_sorting(n, d, k);
    for (int i = 0; i < n; i++) {
      printf("%c", s[P.p[i]]);
    }
    printf("\n");
  }
  return 0;
}
