#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const long long linf = 1e18 + 5;
const int N = 1e6 + 5;
int n, m, k, d, cur[N], res[N], c[N];
char a[N], b[N];
void mul(int a[N], int b[N]) {
  for (int i = 1; i <= n; i++) c[i] = a[b[i]];
  for (int i = 1; i <= n; i++) a[i] = c[i];
}
int main() {
  scanf("%s", a + 1);
  n = strlen(a + 1);
  cin >> m;
  while (m--) {
    scanf("%d %d", &k, &d);
    int cnt = 0;
    for (int i = 0; i <= d - 1; i++)
      for (int j = i; j + 1 <= k; j += d) cur[++cnt] = j + 1;
    for (int i = k + 1; i <= n; i++) cur[i] = i;
    int t = cur[1];
    for (int i = 1; i <= n - 1; i++) cur[i] = cur[i + 1];
    cur[n] = t;
    for (int i = 1; i <= n; i++) res[i] = i;
    int power = n - k + 1;
    for (; power; power >>= 1) {
      if (power & 1) mul(res, cur);
      mul(cur, cur);
    }
    for (int i = k; i <= n; i++) b[i - k + 1] = a[res[i]];
    for (int i = 1; i <= k - 1; i++) b[i + (n - k + 1)] = a[res[i]];
    for (int i = 1; i <= n; i++) a[i] = b[i];
    puts(a + 1);
  }
  return 0;
}
