#include <bits/stdc++.h>
using namespace std;
const int MAX = INT_MAX, MIN = INT_MIN;
void open() {
  freopen("sorting.in", "r", stdin);
  freopen("sorting.out", "w", stdout);
}
void Fail() {
  printf("Fail\n");
  exit(1);
}
char s[1000100];
char g[1000100];
char p[1000100];
int am[1000100];
int fx[1000100];
int tn[1000100];
int n, m, K, D;
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &m);
  for (int _ = 1; _ <= m; ++_) {
    int cnt = 0;
    scanf("%d%d", &K, &D);
    for (int i = 0; i < n; ++i) am[i] = i;
    for (int i = 0; i < D; ++i)
      for (int j = i; j < K; j += D) am[j] = cnt++;
    for (int i = 0; i < n; ++i) fx[i] = am[i == 0 ? n - 1 : i - 1];
    int fang = n - K;
    while (fang) {
      if (fang & 1) {
        for (int i = 0; i < n; ++i) am[i] = fx[am[i]];
      }
      for (int i = 0; i < n; ++i) tn[i] = fx[fx[i]];
      for (int i = 0; i < n; ++i) fx[i] = tn[i];
      fang >>= 1;
    }
    for (int i = 0; i < n; ++i) g[am[i]] = s[i];
    for (int i = 0; i < n; ++i) s[(i + (n - K)) % n] = g[i];
    printf("%s\n", s);
  }
  return 0;
}
