#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, m, p[N], l[N], cnt[N];
char s[N], cur[N];
void mul(int a[], int b[]) {
  static int c[N];
  for (int i = 0; i < n; i++) c[i] = a[b[i]];
  for (int i = 0; i < n; i++) a[i] = c[i];
}
void qpow(int a[], int b) {
  static int c[N];
  for (int i = 0; i < n; i++) c[i] = i;
  while (b) {
    if (b & 1) mul(c, a);
    mul(a, a);
    b >>= 1;
  }
  for (int i = 0; i < n; i++) a[i] = c[i];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> s >> m;
  n = strlen(s);
  for (int i = 0; i < n - 1; i++) l[i] = i + 1;
  for (int i = 1; i <= m; i++) {
    int kk, d;
    cin >> kk >> d;
    for (int j = 0; j < d; j++) cnt[j] = 0;
    for (int j = 0; j < kk; j++) ++cnt[j % d];
    for (int j = 1; j < d; j++) cnt[j] += cnt[j - 1];
    for (int j = kk - 1; j >= 0; --j) p[--cnt[j % d]] = j;
    for (int j = kk; j < n; j++) p[j] = j;
    mul(p, l);
    int tmp = n - kk + 1;
    qpow(p, tmp);
    for (int i = 0; i < n; i++) cur[i] = s[p[i >= tmp ? i - tmp : i + n - tmp]];
    cout << cur << '\n';
    for (int j = 0; j < n; j++) s[j] = cur[j];
  }
  return 0;
}
