#include <bits/stdc++.h>
using namespace std;
int where[20][1000010];
void calc(int k, int p) {
  int cnt = 0;
  for (int i = 0; i < p; i++) {
    for (int j = i; j < k; j += p) {
      where[0][j] = cnt - 1;
      cnt++;
    }
  }
  for (int lg = 1; lg < 20; lg++) {
    for (int i = 0; i < k; i++) {
      if (where[lg - 1][i] == -1)
        where[lg][i] = -1;
      else
        where[lg][i] = where[lg - 1][where[lg - 1][i]];
    }
  }
}
inline int go(int k, int n, int poz) {
  int pstart = max(0, poz - k + 1);
  int loc = poz - pstart;
  for (int i = 19; i >= 0; i--) {
    if (pstart + (1 << i) + k - 1 <= n && where[i][loc] >= 0) {
      loc = where[i][loc];
      pstart += 1 << i;
    }
  }
  return pstart + loc;
}
int ord[2][1000010];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = 0; i < n; i++) ord[0][i] = i;
  int q, p, k, c = 0;
  cin >> q;
  while (q--) {
    cin >> k >> p;
    calc(k, p);
    for (int i = 0; i < n; i++) ord[1 - c][go(k, n, i)] = ord[c][i];
    c = 1 - c;
    for (int i = 0; i < n; i++) cout << s[ord[c][i]];
    cout << '\n';
  }
  return 0;
}
