#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int lft, rght, n, n2, sz, p, p2, tmp, q, k, cnt[30], c[330][30], t[330], a[N];
char ch;
void cntSort(int lft, int rght) {
  int c[30];
  for (int x = 0; x < 26; x++) c[x] = 0;
  for (int i = lft; i <= rght; i++) {
    c[a[i]]++;
  }
  for (int i = lft, x = 25; x >= 0; x--) {
    for (; c[x] > 0; c[x]--, i++) {
      a[i] = x;
    }
  }
}
void cntSort2(int lft, int rght) {
  int c[30];
  for (int x = 0; x < 26; x++) c[x] = 0;
  for (int i = lft; i <= rght; i++) {
    c[a[i]]++;
  }
  for (int i = lft, x = 0; x < 26; x++) {
    for (; c[x] > 0; c[x]--, i++) {
      a[i] = x;
    }
  }
}
void f(int p) {
  for (int j = 0, x = sz * p; j < 26; j++) {
    for (int y = c[p][j]; y > 0; x++, y--) {
      a[x] = j;
    }
  }
  t[p] = 0;
}
void f2(int p) {
  for (int j = 25, x = sz * p; j >= 0; j--) {
    for (int y = c[p][j]; y > 0; x++, y--) {
      a[x] = j;
    }
  }
  t[p] = 0;
}
void f3(int frst, int lst, int p) {
  for (int i = frst; i < lst; i++) {
    cnt[a[i]]++;
    c[p][a[i]]--;
  }
}
void f4(int frst, int lst, int p) {
  for (int x = 0, i = frst; x < 26; x++) {
    for (; i < lst && cnt[x] > 0; i++, cnt[x]--) {
      a[i] = x;
      c[p][x]++;
    }
  }
}
void f5(int j, int x) {
  if (cnt[x] > tmp) {
    c[j][x] = tmp;
    cnt[x] -= tmp;
    tmp = 0;
  } else {
    c[j][x] = cnt[x];
    tmp -= cnt[x];
    cnt[x] = 0;
  }
}
void f6(int frst, int lst, int p) {
  for (int x = 25, i = frst; x >= 0; x--) {
    for (; i < lst && cnt[x] > 0; i++, cnt[x]--) {
      a[i] = x;
      c[p][x]++;
    }
  }
}
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  sz = sqrtl(n);
  n2 = (n - 1) / sz;
  for (int i = 0; i <= n2; i++) {
    t[i] = 0;
    for (int x = 0; x < 26; x++) c[i][x] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> ch;
    a[i] = ch - 'a';
    c[i / sz][a[i]]++;
  }
  for (int i = 1; i <= q; i++) {
    cin >> lft >> rght >> k;
    lft--;
    rght--;
    p = lft / sz;
    p2 = rght / sz;
    if (t[p] == 1)
      f(p);
    else if (t[p] == 2)
      f2(p);
    if (p == p2) {
      if (k == 0)
        cntSort(lft, rght);
      else
        cntSort2(lft, rght);
      continue;
    }
    if (t[p2] == 1)
      f(p2);
    else if (t[p2] == 2)
      f2(p2);
    for (int j = 0; j < 26; j++) cnt[j] = 0;
    f3(lft, sz * (p + 1), p);
    f3(sz * p2, rght + 1, p2);
    for (int j = p + 1; j < p2; j++) {
      for (int x = 0; x < 26; x++) cnt[x] += c[j][x];
    }
    if (k == 1) {
      f4(lft, sz * (p + 1), p);
      for (int j = p + 1; j < p2; j++) {
        if (j == n2)
          tmp = n - (sz * j);
        else
          tmp = sz;
        for (int x = 0; x < 26; x++) {
          f5(j, x);
        }
        t[j] = 1;
      }
      f4(sz * p2, rght + 1, p2);
    } else {
      f6(lft, sz * (p + 1), p);
      for (int j = p + 1; j < p2; j++) {
        if (j == n2)
          tmp = n - (sz * j);
        else
          tmp = sz;
        for (int x = 25; x >= 0; x--) {
          f5(j, x);
        }
        t[j] = 2;
      }
      f6(sz * p2, rght + 1, p2);
    }
  }
  for (int i = 0; i <= n2; i++) {
    if (t[i] == 1)
      f(i);
    else if (t[i] == 2)
      f2(i);
  }
  for (int i = 0; i < n; i++) cout << (char)(a[i] + 'a');
  cout << "\n";
  return 0;
}
