#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
long long int readL() {
  long long int res;
  scanf("%I64d", &res);
  return res;
}
void printL(long long int res) { printf("%I64d", res); }
int n, m;
char s[1000005], t[1000005];
int nxt[1000005], nxt2[1000005];
int conv[1000005], tmp[1000005];
void doit(char* s, int* conv, int k) {
  for (int i = 0; i < (n); ++i) t[conv[i]] = s[i];
  for (int i = 0; i < (n); ++i) s[i] = t[(i + k) % n];
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  cin >> m;
  for (int hoge = 0; hoge < (m); ++hoge) {
    int k, d;
    scanf("%d%d", &k, &d);
    int cnt = 0;
    for (int i = 0; i < (d); ++i)
      for (int j = i; j < k; j += d) nxt[j] = (cnt - 1 + n) % n, ++cnt;
    for (int i = (k); i < (n); ++i) nxt[i] = i - 1;
    for (int i = 0; i < (n); ++i) conv[i] = i;
    for (int i = 0; i < (20); ++i) {
      if ((n + 1 - k) >> i & 1) {
        for (int j = 0; j < (n); ++j) tmp[j] = nxt[conv[j]];
        for (int j = 0; j < (n); ++j) conv[j] = tmp[j];
      }
      for (int j = 0; j < (n); ++j) nxt2[j] = nxt[nxt[j]];
      for (int j = 0; j < (n); ++j) nxt[j] = nxt2[j];
    }
    doit(s, conv, k - 1);
    printf("%s\n", s);
  }
  return 0;
}
