#include <bits/stdc++.h>
using namespace std;
int Q, N;
char s[2000010];
char ns[2000010];
int table[23][2000010];
void show_table(int K, int W) {
  for (int i = 0; i < W; ++i) cout << table[K][i] << " ";
  cout << endl;
}
int main() {
  scanf("%s", s);
  N = strlen(s);
  scanf("%d", &Q);
  while (Q--) {
    int k, d;
    scanf("%d%d", &k, &d);
    int C = N - k + 1;
    for (int i = 0; i < N + C; ++i) table[0][i] = i - 1;
    int at = 0;
    for (int i = 0; i < d; ++i) {
      for (int j = i; j < k; j += d) {
        table[0][j + C] = C + at - 1;
        at++;
      }
    }
    int c = 0;
    while ((1 << c) <= C) c++;
    for (int i = 1; i < c; ++i) {
      for (int j = 0; j < N + C; ++j) {
        if (table[i - 1][j] != -1)
          table[i][j] = table[i - 1][table[i - 1][j]];
        else
          table[i][j] = -1;
      }
    }
    for (int i = 0; i < N; ++i) {
      int at = i + C;
      for (int j = 0; j < c; ++j)
        if (C & (1 << j)) at = table[j][at];
      ns[at] = s[i];
    }
    for (int i = 0; i < N; ++i) s[i] = ns[i];
    printf("%s\n", s);
  }
}
