#include <bits/stdc++.h>
using namespace std;
const int N = 1000000;
int n, m;
string s;
string ans;
int shift[N];
int ssort[N];
int tmp[N];
int temp[N];
void copy(int from[], int to[], int n) {
  for (int i = 0; i < n; i++) {
    to[i] = from[i];
  }
}
void mult(int a[], int b[], int n, int res[]) {
  for (int i = 0; i < n; i++) {
    res[i] = b[a[i]];
  }
}
void pow(int a[], int n, int p, int res[]) {
  for (int i = 0; i < n; i++) {
    tmp[i] = i;
  }
  while (p > 0) {
    if (p % 2 == 1) {
      mult(tmp, a, n, res);
      copy(res, tmp, n);
      p--;
    } else {
      mult(a, a, n, res);
      copy(res, a, n);
      p /= 2;
    }
  }
  copy(tmp, res, n);
}
int main() {
  cin >> s;
  n = s.size();
  ans = s;
  shift[0] = n - 1;
  for (int i = 1; i < n; i++) {
    shift[i] = i - 1;
  }
  scanf("%d", &m);
  while (m--) {
    int k, d;
    scanf("%d%d", &k, &d);
    for (int i = 0; i < n; i++) {
      ssort[i] = i;
    }
    int t = 0;
    for (int i = 0; i < d; i++) {
      for (int j = i; j < k; j += d) {
        ssort[j] = t++;
      }
    }
    mult(ssort, shift, n, tmp);
    copy(tmp, ssort, n);
    pow(ssort, n, n - k + 1, temp);
    copy(temp, ssort, n);
    for (int i = 0; i < n; i++) {
      ans[(ssort[i] - k + 1 + n) % n] = s[i];
    }
    s = ans;
    cout << ans << "\n";
  }
  return 0;
}
