#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> a, b;
vector<int> r;
void carp(vector<int> &a, vector<int> &b) {
  for (long long int i = 0; i <= a.size() - 1; i++) r[i] = a[b[i]];
}
vector<int> fe(vector<int> &a, int b) {
  vector<int> now = a, res;
  int ok = 0;
  while (b) {
    if (b & 1) {
      if (!ok)
        res = now;
      else {
        carp(now, res);
        res = r;
      }
      ok = 1;
    }
    carp(now, now);
    now = r;
    b /= 2;
  }
  return res;
}
int main() {
  cin >> s;
  int m, n;
  n = s.size();
  cin >> m;
  r.resize(s.size());
  while (m--) {
    int k, d;
    scanf("%d %d", &k, &d);
    a.clear();
    for (long long int i = 0; i <= n - 1; i++) a.push_back(i);
    b.resize(n);
    int ind = 0;
    for (long long int i = 0; i <= d - 1; i++)
      for (int j = i; j < k; j += d) b[ind++] = j;
    for (long long int i = k; i <= n - 1; i++) b[i] = i;
    b.push_back(b[0]);
    b.erase(b.begin());
    b = fe(b, n - k + 1);
    a.clear();
    for (long long int i = k - 1; i <= n - 1; i++) a.push_back(b[i]);
    for (long long int i = 0; i <= k - 2; i++) a.push_back(b[i]);
    string res = "";
    for (typeof(a.begin()) it = a.begin(); it != a.end(); it++) res += s[*it];
    s = res;
    printf("%s\n", s.c_str());
  }
}
