#include <bits/stdc++.h>
using namespace std;
char s[1000010];
int n, m, buf[1000010];
template <typename T>
void transform(T* a, int* b) {
  for (int i = 0; i < n; i++) buf[b[i]] = a[i];
  for (int i = 0; i < n; i++) a[i] = buf[i];
}
void add(int* a, int* b) {
  for (int i = 0; i < n; i++) buf[i] = b[a[i]];
  for (int i = 0; i < n; i++) a[i] = buf[i];
}
void apply(int* tmp, int times) {
  while (times) {
    if (times & 1) transform(s, tmp);
    add(tmp, tmp);
    times >>= 1;
  }
}
int a[1000010], b[1000010];
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &m);
  for (int i = 1, ti, tj; i <= m; i++) {
    scanf("%d%d", &ti, &tj);
    int cnt = 0;
    for (int j = 0; j < tj; j++)
      for (int k = j; k < ti; k += tj) a[k] = cnt++;
    for (int j = ti; j < n; j++) a[j] = j;
    for (int j = 1; j < n; j++) b[j] = j - 1;
    b[0] = n - 1;
    add(a, b);
    apply(a, n - ti + 1);
    for (int j = 0; j < n; j++) buf[(j + n - ti + 1) % n] = s[j];
    for (int j = 0; j < n; j++) s[j] = buf[j];
    puts(s);
  }
  return 0;
}
