#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  int N = S.size();
  int M;
  cin >> M;
  while (M-- > 0) {
    int K, D;
    cin >> K >> D;
    vector<int> Move(N);
    int tot = 0;
    for (int i = 0; i < D; ++i) {
      for (int j = i; j < K; j += D) {
        Move[j] = tot++;
      }
    }
    for (int i = K; i < N; ++i) {
      Move[i] = tot++;
    }
    vector<int> P(N);
    for (int i = 0; i < N; ++i) {
      P[i] = Move[i];
    }
    vector<int> X(N);
    for (int i = 0; i < N; ++i) {
      X[i] = Move[(i + N - 1) % N];
    }
    int T = N - K;
    vector<int> tmp(N);
    while (T) {
      if (T & 1) {
        for (int i = 0; i < N; ++i) {
          P[i] = X[P[i]];
        }
      }
      for (int i = 0; i < N; ++i) {
        tmp[i] = X[X[i]];
      }
      for (int i = 0; i < N; ++i) {
        X[i] = tmp[i];
      }
      T >>= 1;
    }
    string B(N, 'a');
    for (int i = 0; i < N; ++i) {
      B[P[i]] = S[i];
    }
    for (int i = 0; i < N; ++i) {
      S[(i + N - K) % N] = B[i];
    }
    cout << S << '\n';
  }
}
