#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int Cnt;
int Row[N << 2], LazyRow[N << 4];
int Col[N << 2], LazyCol[N << 4];
bool visR[N], visC[N];
map<int, int> Hash, invHash;
vector<pair<pair<int, int>, char>> Queries;
void PushLazy(int *Seg, int *Lazy, int Node) {
  if (!Lazy[Node]) return;
  Seg[Node] = max(Seg[Node], Lazy[Node]);
  Lazy[Node << 1] = max(Lazy[Node << 1], Lazy[Node]);
  Lazy[Node << 1 | 1] = max(Lazy[Node << 1 | 1], Lazy[Node]);
  Lazy[Node] = 0;
}
void UpdateRange(int *Seg, int *Lazy, int i, int j, int val, int Node = 1,
                 int L = 1, int R = Cnt) {
  PushLazy(Seg, Lazy, Node);
  if (i > R || j < L) return;
  if (L >= i && R <= j) {
    Lazy[Node] = max(Lazy[Node], val);
    PushLazy(Seg, Lazy, Node);
    return;
  }
  int Mid = L + R >> 1;
  UpdateRange(Seg, Lazy, i, j, val, Node << 1, L, Mid);
  UpdateRange(Seg, Lazy, i, j, val, Node << 1 | 1, Mid + 1, R);
  Seg[Node] = max(Seg[Node << 1], Seg[Node << 1 | 1]);
}
int Query(int *Seg, int *Lazy, int i, int j, int Node = 1, int L = 1,
          int R = Cnt) {
  PushLazy(Seg, Lazy, Node);
  if (i > R || j < L) return 0;
  if (L >= i && R <= j) return Seg[Node];
  int Mid = L + R >> 1;
  int Q1 = Query(Seg, Lazy, i, j, Node << 1, L, Mid);
  int Q2 = Query(Seg, Lazy, i, j, Node << 1 | 1, Mid + 1, R);
  return max(Q1, Q2);
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  while (q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    char ch;
    scanf(" %c", &ch);
    Hash[x];
    Hash[y];
    Queries.push_back({{x, y}, ch});
  }
  for (auto &x : Hash) {
    x.second = ++Cnt;
    invHash[Cnt] = x.first;
  }
  for (auto query : Queries) {
    int x = Hash[query.first.first];
    int y = Hash[query.first.second];
    char c = query.second;
    if (c == 'U') {
      if (visC[y]) {
        puts("0");
        continue;
      }
      int cur = Query(Col, LazyCol, x, x);
      printf("%d\n", invHash[y] - invHash[cur]);
      UpdateRange(Row, LazyRow, cur, y, x);
      visC[y] = true;
    } else {
      if (visR[x]) {
        puts("0");
        continue;
      }
      int cur = Query(Row, LazyRow, y, y);
      printf("%d\n", invHash[x] - invHash[cur]);
      UpdateRange(Col, LazyCol, cur, x, y);
      visR[x] = true;
    }
  }
  return 0;
}
