#include <bits/stdc++.h>
#pragma comment(linker, "/STATK:134217728")
using namespace std;
int n, q;
char s[1 << 17];
struct P {
  int L, R;
  char c;
  P() {}
  P(int L, int R, char c) : L(L), R(R), c(c) {}
};
bool operator<(const P& a, const P& b) { return a.L < b.L; }
int cnt[26];
int main() {
  set<P> S;
  scanf("%d%d", &n, &q);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) S.insert(P(i, i + 1, s[i]));
  while (q-- > 0) {
    int i, j, k;
    scanf("%d%d%d", &i, &j, &k);
    i--;
    memset(cnt, 0, sizeof(cnt));
    set<P>::iterator it = S.upper_bound(P(i, j, '0'));
    it--;
    if (it->L <= i && j <= it->R) continue;
    cnt[it->c - 'a'] += it->R - i;
    int L = it->L, R = it->R;
    char c = it->c;
    S.erase(it);
    if (L != i) S.insert(P(L, i, c));
    while (1) {
      it = S.upper_bound(P(i, j, '0'));
      if (j <= it->R) {
        cnt[it->c - 'a'] += j - it->L;
        int L = it->L, R = it->R;
        char c = it->c;
        S.erase(it);
        if (R != j) S.insert(P(j, R, c));
        break;
      }
      cnt[it->c - 'a'] += it->R - it->L;
      S.erase(it);
    }
    int add = 0;
    if (k) {
      for (int it = 0; it < 26; ++it) {
        if (cnt[it] > 0) {
          S.insert(P(i + add, i + add + cnt[it], 'a' + it));
          add += cnt[it];
        }
      }
    } else {
      for (int it = 25; it >= 0; --it) {
        if (cnt[it] > 0) {
          S.insert(P(i + add, i + add + cnt[it], 'a' + it));
          add += cnt[it];
        }
      }
    }
  }
  for (set<P>::iterator it = S.begin(); it != S.end(); ++it)
    for (int j = 0; j < it->R - it->L; ++j) printf("%c", it->c);
  printf("\n");
  return 0;
}

### Prompt

Please formulate a CPP solution to the following problem:

This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from i to j in non-decreasing order if k = 1 or in non-increasing order if k = 0.

Output the final string after applying the queries.

Input

The first line will contain two integers n, q (1 ≤ n ≤ 105, 0 ≤ q ≤ 50 000), the length of the string and the number of queries respectively. 

Next line contains a string S itself. It contains only lowercase English letters.

Next q lines will contain three integers each i, j, k (1 ≤ i ≤ j ≤ n, <image>).

Output

Output one line, the string S after applying the queries.

Examples

Input

10 5
abacdabcda
7 10 0
5 8 1
1 4 0
3 6 0
7 10 1


Output

cbcaaaabdd

Input

10 1
agjucbvdfk
1 10 1


Output

abcdfgjkuv

Note

First sample test explanation:

<image>

<image>

<image>

<image>

<image>

### Response

```cpp
#include <bits/stdc++.h>
#pragma comment(linker, "/STATK:134217728")
using namespace std;
int n, q;
char s[1 << 17];
struct P {
  int L, R;
  char c;
  P() {}
  P(int L, int R, char c) : L(L), R(R), c(c) {}
};
bool operator<(const P& a, const P& b) { return a.L < b.L; }
int cnt[26];
int main() {
  set<P> S;
  scanf("%d%d", &n, &q);
  scanf("%s", s);
  for (int i = 0; i < n; ++i) S.insert(P(i, i + 1, s[i]));
  while (q-- > 0) {
    int i, j, k;
    scanf("%d%d%d", &i, &j, &k);
    i--;
    memset(cnt, 0, sizeof(cnt));
    set<P>::iterator it = S.upper_bound(P(i, j, '0'));
    it--;
    if (it->L <= i && j <= it->R) continue;
    cnt[it->c - 'a'] += it->R - i;
    int L = it->L, R = it->R;
    char c = it->c;
    S.erase(it);
    if (L != i) S.insert(P(L, i, c));
    while (1) {
      it = S.upper_bound(P(i, j, '0'));
      if (j <= it->R) {
        cnt[it->c - 'a'] += j - it->L;
        int L = it->L, R = it->R;
        char c = it->c;
        S.erase(it);
        if (R != j) S.insert(P(j, R, c));
        break;
      }
      cnt[it->c - 'a'] += it->R - it->L;
      S.erase(it);
    }
    int add = 0;
    if (k) {
      for (int it = 0; it < 26; ++it) {
        if (cnt[it] > 0) {
          S.insert(P(i + add, i + add + cnt[it], 'a' + it));
          add += cnt[it];
        }
      }
    } else {
      for (int it = 25; it >= 0; --it) {
        if (cnt[it] > 0) {
          S.insert(P(i + add, i + add + cnt[it], 'a' + it));
          add += cnt[it];
        }
      }
    }
  }
  for (set<P>::iterator it = S.begin(); it != S.end(); ++it)
    for (int j = 0; j < it->R - it->L; ++j) printf("%c", it->c);
  printf("\n");
  return 0;
}

```