#include <bits/stdc++.h>
using namespace std;
string s;
int n;
vector<int> curr;
vector<int> mult(vector<int> &a, vector<int> &b) {
  vector<int> c;
  c.resize(a.size());
  for (int i = 0; i < a.size(); i++) {
    c[i] = a[b[i]];
  }
  return c;
}
vector<int> find_pow(vector<int> a, int po) {
  int k = int(a.size());
  vector<int> b(k);
  for (int i = 0; i < k; ++i) {
    b[i] = i;
  }
  while (po) {
    if (po % 2 == 1) {
      b = mult(b, a);
    }
    a = mult(a, a);
    po /= 2;
  }
  return b;
}
void go(int k, int d) {
  vector<int> res1;
  vector<int> res2;
  vector<int> res;
  for (int i = 0; i < d; i++) {
    for (int j = i; j < k; j += d) {
      res1.push_back(j);
    }
  }
  for (int i = k; i < n; i++) res1.push_back(i);
  for (int i = 1; i < n; i++) res2.push_back(i);
  res2.push_back(0);
  res = mult(res1, res2);
  res = find_pow(res, n - k + 1);
  vector<int> res4;
  for (int i = k - 1; i < n; i++) res4.push_back(i);
  for (int i = 0; i < k - 1; i++) res4.push_back(i);
  res = mult(res, res4);
  curr = mult(curr, res);
}
int main() {
  int q;
  cin >> s >> q;
  n = s.length();
  for (int i = 0; i < n; i++) curr.push_back(i);
  for (int i = 1; i <= q; i++) {
    int k, d;
    scanf("%d %d", &k, &d);
    go(k, d);
    for (int j = 0; j < curr.size(); j++) {
      printf("%c", s[curr[j]]);
    }
    printf("\n");
  }
  return 0;
}
