#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool maxit(T& a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool minit(T& a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
inline long long gint() {
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') {
      f = -1;
    }
    c = getchar();
  }
  long long a = c - '0';
  while ((c = getchar()) >= '0' && c <= '9') {
    a = a * 10 + c - '0';
  }
  return a * f;
}
const int maxn = 1000010;
char s[maxn];
int n;
int shift[maxn], d_sort[maxn];
void permute_mul(int* a, int* b, int* res) {
  static int c[maxn];
  for (int i = 0; i < n; i++) {
    c[i] = b[a[i]];
  }
  for (int i = 0; i < n; i++) {
    res[i] = c[i];
  }
}
void permute_pow(int* p, int k, int* res) {
  static int r[maxn], a[maxn];
  for (int i = 0; i < n; i++) {
    r[i] = i;
    a[i] = p[i];
  }
  while (k) {
    if (k & 1) {
      permute_mul(r, a, r);
    }
    if (!(k >>= 1)) {
      break;
    }
    permute_mul(a, a, a);
  }
  for (int i = 0; i < n; i++) {
    res[i] = r[i];
  }
}
void transform(char* s, int* T, char* res) {
  static char t[maxn];
  for (int i = 0; i < n; i++) {
    t[T[i]] = s[i];
  }
  for (int i = 0; i < n; i++) {
    res[i] = t[i];
  }
  res[n] = 0;
}
int T[maxn];
int main() {
  fgets(s, sizeof(s), stdin);
  n = strlen(s);
  while (isspace(s[n - 1])) {
    s[--n] = 0;
  }
  int m = gint();
  for (int i = 0; i < n; i++) {
    shift[i] = i - 1;
  }
  shift[0] = n - 1;
  while (m--) {
    int k = gint(), d = gint();
    for (int i = 0, vn = 0; i < d; i++) {
      for (int j = i; j < k; j += d) {
        d_sort[j] = vn++;
      }
    }
    for (int i = k; i < n; i++) {
      d_sort[i] = i;
    }
    permute_mul(d_sort, shift, T);
    permute_pow(T, n - k + 1, T);
    transform(s, T, s);
    permute_pow(shift, k - 1, T);
    transform(s, T, s);
    puts(s);
  }
  return 0;
}
