#include <bits/stdc++.h>
using namespace std;
int ch[10010][2], fa[10010], sz[10010];
char key[10010], s[10010];
int root, tot;
int dir(int x) { return x == ch[fa[x]][1]; }
void update(int x) { sz[x] = sz[ch[x][0]] + sz[ch[x][1]] + 1; }
void updateroot(int x) {
  for (; x != 0; x = fa[x]) update(x);
}
void rotate(int x) {
  int y = fa[x], b = dir(x);
  int z = fa[y], a = ch[x][!b];
  if (z == 0)
    root = x;
  else
    ch[z][dir(y)] = x;
  fa[x] = z;
  ch[x][!b] = y;
  fa[y] = x;
  ch[y][b] = a;
  if (a != 0) fa[a] = y;
  update(y);
  update(x);
}
void splay(int x, int i) {
  for (; fa[x] != i;) {
    int y = fa[x];
    int z = fa[y];
    if (z == i)
      rotate(x);
    else {
      int b = dir(x);
      int c = dir(y);
      if (b ^ c) {
        rotate(x);
        rotate(x);
      } else {
        rotate(y);
        rotate(x);
      }
    }
  }
}
int find_min(int i) {
  for (; ch[i][0] != 0; i = ch[i][0])
    ;
  return i;
}
int find_max(int i) {
  for (; ch[i][1] != 0; i = ch[i][1])
    ;
  return i;
}
int find_k(int i, int k) {
  if (sz[ch[i][0]] == k - 1) return i;
  if (sz[ch[i][0]] > k - 1)
    return find_k(ch[i][0], k);
  else
    return find_k(ch[i][1], k - sz[ch[i][0]] - 1);
}
void build(int f, int d, int l, int r) {
  int mid = (l + r) >> 1;
  fa[++tot] = f;
  ch[f][d] = tot;
  sz[tot] = 1;
  key[tot] = s[mid];
  int u = tot;
  if (l < mid) build(u, 0, l, mid - 1);
  if (r > mid) build(u, 1, mid + 1, r);
  update(u);
}
void dfs(int x) {
  if (ch[x][0]) dfs(ch[x][0]);
  if (x != 1 && x != 2) printf("%c", key[x]);
  if (ch[x][1]) dfs(ch[x][1]);
}
int main() {
  scanf("%s", s + 1);
  root = 1;
  tot = 2;
  ch[1][0] = 0;
  ch[1][1] = 2;
  fa[1] = 0;
  sz[1] = 2;
  key[1] = 0;
  ch[2][0] = ch[2][1] = 0;
  fa[2] = 1;
  sz[2] = 1;
  key[2] = 0;
  int n = strlen(s + 1);
  build(2, 0, 1, n);
  updateroot(3);
  int m;
  scanf("%d", &m);
  for (; m--;) {
    int l, r, k;
    scanf("%d%d%d", &l, &r, &k);
    k %= r - l + 1;
    if (!k) continue;
    int w = find_k(root, r - k + 1);
    splay(w, 0);
    int u = find_k(root, r + 2);
    splay(u, w);
    int tmp = ch[u][0];
    ch[u][0] = fa[tmp] = 0;
    updateroot(u);
    w = find_k(root, l);
    splay(w, 0);
    u = find_k(root, l + 1);
    splay(u, w);
    ch[u][0] = tmp;
    fa[tmp] = u;
    updateroot(u);
  }
  dfs(root);
  printf("\n");
  return 0;
}
