#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
vector<int> operator*(const vector<int>& A, const vector<int>& B) {
  vector<int> C(A.size());
  for (int i = 0; i < A.size(); ++i) C[i] = A[B[i]];
  return C;
}
void print(vector<int>& P) {
  for (int i = 0; i < P.size(); ++i) cout << P[i] << " ";
  cout << endl;
}
int n, m, k, d;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s >> m;
  n = s.size();
  vector<int> P(n), S(n);
  for (int i = 0; i < n; ++i) S[i] = i;
  while (m--) {
    cin >> k >> d;
    for (int i = 0; i < n; ++i) P[i] = i;
    int y = 0;
    for (int i = 0; i < d; ++i)
      for (int j = i; j < k; j += d) P[y++] = j;
    rotate(P.begin(), P.begin() + 1, P.end());
    y = n - k + 1;
    while (y) {
      if (y & 1) S = S * P;
      P = P * P;
      y >>= 1;
    }
    rotate(S.begin(), S.begin() + k - 1, S.end());
    for (int i = 0; i < n; ++i) putchar(s[S[i]]);
    puts("");
  }
  return 0;
}
