#include <bits/stdc++.h>
using namespace std;
const int nsz = 1e6;
char s[nsz + 5], t[nsz + 5];
int n, m;
vector<int> e, l;
vector<int> inline operator*(const vector<int> &a, const vector<int> &b) {
  vector<int> r(n);
  for (int i = 0; i < a.size(); ++i) r[i] = b[a[i]];
  return r;
}
vector<int> inline operator*=(vector<int> &a, const vector<int> &b) {
  return a = a * b;
}
vector<int> inline pow(const vector<int> &w, int p) {
  vector<int> r = e, a = w;
  for (; p > 0; a *= a, p >>= 1)
    if (p & 1) r *= a;
  return r;
}
void inline operate(int k, int d) {
  vector<int> p(n);
  int b = 0, it = 0;
  for (int i = 0; i < k; ++i) {
    p[it] = i;
    if ((it += d) >= k) it = ++b;
  }
  for (int i = k; i <= n - 1; ++i) p[i] = i;
  p = pow(p * l, n - k + 1);
  for (int i = 0; i < n; ++i) t[p[i]] = s[i];
  for (int i = 0; i < n; ++i) s[i] = t[(i + k - 1) % n];
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  scanf("%d", &m);
  for (int i = 0; i < n; ++i) e.push_back(i);
  l.push_back(n - 1);
  for (int i = 1; i <= n - 1; ++i) l.push_back(i - 1);
  for (int i = 1; i <= m; ++i) {
    int k, d;
    scanf("%d%d", &k, &d);
    operate(k, d);
    printf("%s\n", s);
  }
}
