#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
int n, m, q, A[M], B[M], a[M], b[M], c[M];
bool mark[M];
char str[2];
struct T {
  int val;
  T() { val = 0; }
} T[2][4 * M];
void Max(int &a, int b) { a = max(a, b); }
void down(int p, bool f) {
  int v = T[f][p].val;
  Max(T[f][p << 1].val, v);
  Max(T[f][p << 1 | 1].val, v);
}
void update(int L, int R, int p, int l, int r, int mx, bool f) {
  int mid = L + R >> 1;
  if (r < L || l > R) return;
  if (l <= L && r >= R) {
    Max(T[f][p].val, mx);
    return;
  }
  update(L, mid, p << 1, l, r, mx, f);
  update(mid + 1, R, p << 1 | 1, l, r, mx, f);
}
int query(int L, int R, int p, int x, bool f) {
  if (L == R) {
    return T[f][p].val;
  }
  down(p, f);
  int mid = L + R >> 1;
  if (x <= mid)
    return query(L, mid, p << 1, x, f);
  else
    return query(mid + 1, R, p << 1 | 1, x, f);
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", a + i, b + i);
    A[i] = a[i];
    B[i] = b[i];
    scanf("%s", str);
    c[i] = (str[0] == 'U');
  }
  sort(A + 1, A + q + 1);
  sort(B + 1, B + q + 1);
  m = unique(A + 1, A + q + 1) - A - 1;
  m = unique(B + 1, B + q + 1) - B - 1;
  for (int i = 1; i <= q; i++) {
    a[i] = lower_bound(A + 1, A + 1 + m, a[i]) - A;
    b[i] = lower_bound(B + 1, B + 1 + m, b[i]) - B;
  }
  for (int i = 1; i <= q; i++) {
    if (mark[a[i]]) {
      puts("0");
      continue;
    }
    mark[a[i]] = 1;
    if (c[i]) {
      int t = query(1, m, 1, a[i], 1);
      update(1, m, 1, t, b[i], a[i], 0);
      printf("%d\n", B[b[i]] - B[t]);
    } else {
      int t = query(1, m, 1, b[i], 0);
      update(1, m, 1, t, a[i], b[i], 1);
      printf("%d\n", A[a[i]] - A[t]);
    }
  }
  return 0;
}
