#include <bits/stdc++.h>
using namespace std;
int N, M, k, d;
vector<int> id;
vector<int> tmp1;
vector<int> tmp2;
vector<int> tmp3;
vector<int> tmp4;
string S;
static const int maxn = 1e6 + 5;
char s[maxn];
void mult(const vector<int>& a, const vector<int>& b, vector<int>& ret) {
  assert(a.size() == N);
  assert(b.size() == N);
  assert(ret.size() == N);
  for (int i = 0; i < N; i++) {
    ret[i] = a[b[i]];
  }
}
void power(const vector<int>& a, int p, vector<int>& ret) {
  if (p == 1) {
    ret = a;
    return;
  }
  assert(a.size() == N);
  ret.clear();
  ret = id;
  tmp1 = a;
  assert(ret.size() == N);
  while (p > 0) {
    if (p % 2 == 0) {
      p = p / 2;
      mult(tmp1, tmp1, tmp2);
      tmp1 = tmp2;
    } else {
      p--;
      mult(ret, tmp1, tmp2);
      ret = tmp2;
    }
  }
}
void print(const string& s, const vector<int>& shuffle) {
  string r = s;
  for (int i = 0; i < N; i++) {
    r[i] = s[shuffle[i]];
  }
  cout << r.c_str() << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  scanf("%s", s);
  S = string(s);
  N = S.size();
  for (int i = 0; i < N; i++) {
    id.push_back(i);
  }
  tmp1 = id;
  tmp2 = id;
  tmp3 = id;
  tmp4 = id;
  vector<int> shuffle(id);
  vector<int> C(N, 0);
  for (int i = 0; i < N - 1; i++) {
    C[i] = i + 1;
  }
  C[N - 1] = 0;
  scanf("%d", &M);
  for (int m = 0; m < M; m++) {
    scanf("%d%d", &k, &d);
    if (d > 1) {
      int curr = 0;
      vector<int> P(N, 0);
      for (int i = 0; i < k; i++) {
        if (curr >= k) {
          curr = (curr % d) + 1;
        }
        P[i] = curr;
        curr += d;
      }
      for (int i = k; i < N; i++) {
        P[i] = i;
      }
      mult(P, C, tmp3);
      P = tmp3;
      power(P, N - k + 1, tmp3);
      mult(shuffle, tmp3, tmp4);
      power(C, k - 1, tmp3);
      mult(tmp4, tmp3, shuffle);
    }
    print(S, shuffle);
  }
  return 0;
}
