#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  int l = v.size();
  for (int i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
void tr() { cout << endl; }
template <typename S, typename... Strings>
void tr(S x, const Strings&... rest) {
  cout << x << ' ';
  tr(rest...);
}
const int LOGN = 20;
const int N = 1 << LOGN;
string s;
int n, m;
int pos[LOGN][N];
int cnt[N];
int get(int x, int k) {
  int res = 0;
  if (x >= k) {
    res = x - k + 1;
    x = k - 1;
  }
  for (int i = LOGN - 1; i >= 0; i--) {
    if (pos[i][x] != -1 and res + k - 1 + (1 << i) - 1 < n) {
      res += (1 << i) - 1;
      x = pos[i][x];
      if (res + k < n and x > 0) {
        x--;
        res++;
      } else
        break;
    }
  }
  res += x;
  return res;
}
void update() {
  int k, d;
  cin >> k >> d;
  fill(cnt, cnt + n, 0);
  int cur = 0;
  for (int i = 0; i < d; i++) {
    for (int j = i; j < k; j += d) {
      pos[0][j] = cur++;
    }
  }
  for (int j = 1; j < LOGN; j++) {
    for (int i = 0; i < k; i++) {
      pos[j][i] = (pos[j - 1][i] <= 0) ? -1 : pos[j - 1][pos[j - 1][i] - 1];
    }
  }
  string t = s;
  for (int i = 0; i < n; i++) {
    int j = get(i, k);
    t[j] = s[i];
  }
  s = t;
  cout << s << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> s;
  n = s.length();
  cin >> m;
  while (m--) {
    update();
  }
  return 0;
}
