#include <bits/stdc++.h>
using namespace std;
int n, q;
string second;
int segtree[26][400005], lazy[26][400005];
void build(int v, int l, int r) {
  if (l == r) {
    segtree[second[l] - 'a'][v] = 1;
    lazy[second[l] - 'a'][v] = -1;
    return;
  }
  int m = (l + r) / 2;
  build(2 * v, l, m);
  build(2 * v + 1, m + 1, r);
  for (int i = 0; i < 26; ++i) {
    segtree[i][v] = segtree[i][2 * v] + segtree[i][2 * v + 1];
    lazy[i][v] = -1;
  }
}
void push(int v, int c, int l, int r) {
  if (lazy[c][v] != -1) {
    if (l != r) {
      lazy[c][2 * v + 1] = lazy[c][v];
      lazy[c][2 * v] = lazy[c][v];
    }
    segtree[c][v] = (r - l + 1) * lazy[c][v];
    lazy[c][v] = -1;
  }
}
void update(int v, int l, int r, int ql, int qr, int val, int c) {
  push(v, c, l, r);
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    segtree[c][v] = (r - l + 1) * val;
    if (l != r) lazy[c][2 * v] = lazy[c][2 * v + 1] = val;
    return;
  }
  push(v, c, l, r);
  int m = (l + r) / 2;
  update(2 * v, l, m, ql, qr, val, c);
  update(2 * v + 1, m + 1, r, ql, qr, val, c);
  segtree[c][v] = segtree[c][2 * v] + segtree[c][2 * v + 1];
}
int query(int v, int l, int r, int ql, int qr, int c) {
  push(v, c, l, r);
  if (l > qr || r < ql) return 0;
  if (ql <= l && r <= qr) return segtree[c][v];
  push(v, c, l, r);
  int m = (l + r) / 2;
  return query(2 * v, l, m, ql, qr, c) + query(2 * v + 1, m + 1, r, ql, qr, c);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  cin >> second;
  int cnt[26];
  memset(cnt, 0, sizeof cnt);
  build(1, 0, n - 1);
  while (q--) {
    int x, y, k;
    cin >> x >> y >> k;
    x--;
    y--;
    for (int i = 0; i < 26; ++i) {
      cnt[i] = query(1, 0, n - 1, x, y, i);
      if (cnt[i]) update(1, 0, n - 1, x, y, 0, i);
    }
    if (k) {
      for (int i = 0; i < 26; ++i) {
        if (cnt[i] == 0) continue;
        update(1, 0, n - 1, x, x + cnt[i] - 1, 1, i);
        x += cnt[i];
      }
    } else {
      for (int i = 0; i < 26; ++i) {
        if (cnt[i] == 0) continue;
        update(1, 0, n - 1, y - cnt[i] + 1, y, 1, i);
        y -= cnt[i];
      }
    }
  }
  string ans;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      int a = query(1, 0, n - 1, i, i, j);
      if (a) {
        ans += ('a' + j);
        break;
      }
    }
  }
  cout << ans;
}

### Prompt

Please create a solution in cpp 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>
using namespace std;
int n, q;
string second;
int segtree[26][400005], lazy[26][400005];
void build(int v, int l, int r) {
  if (l == r) {
    segtree[second[l] - 'a'][v] = 1;
    lazy[second[l] - 'a'][v] = -1;
    return;
  }
  int m = (l + r) / 2;
  build(2 * v, l, m);
  build(2 * v + 1, m + 1, r);
  for (int i = 0; i < 26; ++i) {
    segtree[i][v] = segtree[i][2 * v] + segtree[i][2 * v + 1];
    lazy[i][v] = -1;
  }
}
void push(int v, int c, int l, int r) {
  if (lazy[c][v] != -1) {
    if (l != r) {
      lazy[c][2 * v + 1] = lazy[c][v];
      lazy[c][2 * v] = lazy[c][v];
    }
    segtree[c][v] = (r - l + 1) * lazy[c][v];
    lazy[c][v] = -1;
  }
}
void update(int v, int l, int r, int ql, int qr, int val, int c) {
  push(v, c, l, r);
  if (l > qr || r < ql) return;
  if (ql <= l && r <= qr) {
    segtree[c][v] = (r - l + 1) * val;
    if (l != r) lazy[c][2 * v] = lazy[c][2 * v + 1] = val;
    return;
  }
  push(v, c, l, r);
  int m = (l + r) / 2;
  update(2 * v, l, m, ql, qr, val, c);
  update(2 * v + 1, m + 1, r, ql, qr, val, c);
  segtree[c][v] = segtree[c][2 * v] + segtree[c][2 * v + 1];
}
int query(int v, int l, int r, int ql, int qr, int c) {
  push(v, c, l, r);
  if (l > qr || r < ql) return 0;
  if (ql <= l && r <= qr) return segtree[c][v];
  push(v, c, l, r);
  int m = (l + r) / 2;
  return query(2 * v, l, m, ql, qr, c) + query(2 * v + 1, m + 1, r, ql, qr, c);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  cin >> second;
  int cnt[26];
  memset(cnt, 0, sizeof cnt);
  build(1, 0, n - 1);
  while (q--) {
    int x, y, k;
    cin >> x >> y >> k;
    x--;
    y--;
    for (int i = 0; i < 26; ++i) {
      cnt[i] = query(1, 0, n - 1, x, y, i);
      if (cnt[i]) update(1, 0, n - 1, x, y, 0, i);
    }
    if (k) {
      for (int i = 0; i < 26; ++i) {
        if (cnt[i] == 0) continue;
        update(1, 0, n - 1, x, x + cnt[i] - 1, 1, i);
        x += cnt[i];
      }
    } else {
      for (int i = 0; i < 26; ++i) {
        if (cnt[i] == 0) continue;
        update(1, 0, n - 1, y - cnt[i] + 1, y, 1, i);
        y -= cnt[i];
      }
    }
  }
  string ans;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      int a = query(1, 0, n - 1, i, i, j);
      if (a) {
        ans += ('a' + j);
        break;
      }
    }
  }
  cout << ans;
}

```