#include <bits/stdc++.h>
using namespace std;
const int L = 10002;
const int Q = 300;
char s[L];
int n;
void get_seg(int p, vector<pair<int, int> >& sg, int& id, int& acc) {
  id = 0, acc = 0;
  for (; id < sg.size() && p > acc + sg[id].second - sg[id].first + 1; ++id) {
    acc += sg[id].second - sg[id].first + 1;
  }
}
void split(int p, vector<pair<int, int> >& sg) {
  if (p > n) {
    return;
  }
  int j, acc;
  get_seg(p, sg, j, acc);
  int rp = p - acc - 1;
  if (rp) {
    sg.insert(sg.begin() + j, sg[j]);
    sg[j].second = sg[j].first + rp - 1;
    sg[j + 1].first = sg[j].first + rp;
  }
}
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  int q;
  scanf("%d", &q);
  vector<pair<int, int> > sg;
  sg.push_back(pair<int, int>(1, n));
  while (q--) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    k = r - k % (r - l + 1);
    if (k == 0) {
      continue;
    }
    split(l, sg);
    split(k + 1, sg);
    split(r + 1, sg);
    int acc, il, ik, ir;
    get_seg(l, sg, il, acc);
    get_seg(k + 1, sg, ik, acc);
    get_seg(r + 1, sg, ir, acc);
    vector<pair<int, int> > nw;
    nw.insert(nw.end(), sg.begin(), sg.begin() + il);
    nw.insert(nw.end(), sg.begin() + ik, sg.begin() + ir);
    nw.insert(nw.end(), sg.begin() + il, sg.begin() + ik);
    nw.insert(nw.end(), sg.begin() + ir, sg.end());
    sg = nw;
  }
  for (auto qs : sg) {
    for (int i = qs.first; i <= qs.second; ++i) {
      printf("%c", s[i]);
    }
  }
  puts("");
  return 0;
}
