#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000000 + 7;
int bs(int *st, int *en, int val, char c) {
  int k;
  if (c == 'l') k = lower_bound(st, en, val) - st;
  if (c == 'u') k = upper_bound(st, en, val) - st;
  return k;
}
set<int> sx;
set<int> sy;
int ans[200005];
map<int, int> mx, my, m;
int xl, yl;
struct inp {
  int x;
  int y;
  char c;
};
inp in[2 * 100005];
struct st {
  int mx;
  bool is;
};
vector<st> vx(4 * 8 * 100005);
vector<st> vy(4 * 8 * 100005);
void build(int lo, int hi, int at, vector<st> &v) {
  v[at].is = false;
  v[at].mx = 0;
  if (lo == hi) return;
  int mid = (lo + hi) / 2;
  build(lo, mid, 2 * at, v);
  build(mid + 1, hi, 2 * at + 1, v);
}
void undo_lazy(int at, vector<st> &v) {
  if (!v[at].is) return;
  v[at].is = false;
  v[2 * at].is = v[2 * at + 1].is = true;
  v[2 * at].mx = max(v[2 * at].mx, v[at].mx);
  v[2 * at + 1].mx = max(v[2 * at + 1].mx, v[at].mx);
}
void update(int lo, int hi, int at, int from, int to, vector<st> &v, int val) {
  if (lo != hi) undo_lazy(at, v);
  if (lo == from && hi == to) {
    v[at].is = true;
    v[at].mx = max(v[at].mx, val);
    return;
  }
  int mid = (lo + hi) / 2;
  if (to <= mid) {
    update(lo, mid, 2 * at, from, to, v, val);
  } else {
    if (from > mid) {
      update(mid + 1, hi, 2 * at + 1, from, to, v, val);
    } else {
      update(lo, mid, 2 * at, from, mid, v, val);
      update(mid + 1, hi, 2 * at + 1, mid + 1, to, v, val);
    }
  }
}
int q(int lo, int hi, int at, vector<st> &v, int pos) {
  if (lo != hi) undo_lazy(at, v);
  if (lo == hi) return v[at].mx;
  int mid = (lo + hi) / 2;
  if (pos <= mid)
    return q(lo, mid, 2 * at, v, pos);
  else
    return q(mid + 1, hi, 2 * at + 1, v, pos);
}
int main() {
  int a, b, c, d, e, x, y, z, n, qu;
  char ch;
  sx.clear();
  sy.clear();
  mx.clear();
  my.clear();
  sx.insert(0);
  sy.insert(0);
  scanf("%d %d", &n, &qu);
  set<int>::iterator i;
  for (a = 0; a < qu; a++) {
    scanf("%d %d %c", &in[a].x, &in[a].y, &in[a].c);
    sx.insert(in[a].x);
    sy.insert(in[a].y);
  }
  xl = yl = 0;
  for (i = sx.begin(); i != sx.end(); i++) {
    ++xl;
    mx[*i] = xl;
  }
  build(1, xl, 1, vx);
  for (i = sy.begin(); i != sy.end(); i++) {
    ++yl;
    my[*i] = yl;
  }
  build(1, yl, 1, vy);
  m.clear();
  for (a = 0; a < qu; a++) {
    x = in[a].x;
    y = in[a].y;
    ch = in[a].c;
    if (m[x]) {
      printf("0\n");
      continue;
    }
    m[x] = 1;
    if (ch == 'U') {
      z = q(1, xl, 1, vx, mx[x]);
      printf("%d\n", y - z);
      update(1, yl, 1, my[z], my[y], vy, x);
    } else {
      z = q(1, yl, 1, vy, my[y]);
      printf("%d\n", x - z);
      update(1, xl, 1, mx[z], mx[x], vx, y);
    }
  }
  return 0;
}
