#include <bits/stdc++.h>
#define loop(i,n) for(int i = 0;i < (n);i++)
#define range(i,a,b) for(int i = (a);i <= (b);i++)
#define all(A) A.begin(),A.end()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define sz(A) ((int)A.size())
#define vi vector<int>
#define vl vector<long long>
#define vd vector<double>
#define vp vector<pair<int,int> >
#define ll long long
#define pi pair<int,int>
#define point pair<double,double>
#define pl pair<ll,ll>
#define popcnt(x) __builtin_popcount(x)
#define LSOne(x) ((x) & (-(x)))
#define xx first
#define yy second
#define PQ priority_queue
#define print(A,t) cerr << #A << ": "; copy(all(A),ostream_iterator<t>(cerr," " )); cerr << endl
#define prp(p) cerr << "(" << (p).first << " ," << (p).second << ")";
#define prArr(A,n,t)  cerr << #A << ": "; copy(A,A + n,ostream_iterator<t>(cerr," " )); cerr << endl
#define PRESTDIO() cin.tie(0),cerr.tie(0),ios_base::sync_with_stdio(0)
using namespace std;

const int MAX = 2e5 + 1e2;
int n,m;
int X[MAX],Y[MAX],F[MAX],G[MAX],k1,k2;
char type[MAX];
int ST[2][MAX << 2];
set<int> S;

void compress(int *X,int *F,int & k){
	sort(F,F + m + 1);
	k = unique(F,F + m + 1) - F;
	loop(i,m) X[i] = lower_bound(F,F + k,X[i]) - F;
}

void update(int node,int s,int e,int l,int r,int v,int *T){
	if(l <= s && e <= r){
		T[node] = max(T[node],v);
		return;
	}
	int m = (s + e) >> 1,left = node << 1,right = left | 1;
	if(r <= m) update(left,s,m,l,r,v,T);
	else if(m < l) update(right,m+1,e,l,r,v,T);
	else update(left,s,m,l,m,v,T),update(right,m+1,e,m+1,r,v,T);
}

int query(int node,int s,int e,int p,int *T){
	if(s == e) return T[node];
	int m = (s + e) >> 1,left = node << 1,right = left | 1;
	if(p <= m) return max(T[node],query(left,s,m,p,T));
	else return max(T[node],query(right,m+1,e,p,T));
}

int main(){
	scanf("%d %d",&n,&m);
	loop(i,m){
		scanf("%d %d %c",X + i,Y + i,&type[i]);
		swap(X[i],Y[i]);
		F[i] = X[i];
		G[i] = Y[i];
	}
	compress(X,F,k1);
	compress(Y,G,k2);
	loop(i,m){
		if(S.find(X[i]) != S.end()){
			puts("0");
			continue;
		}
		//cerr << X[i] << " " << Y[i] << endl;
		if(type[i] == 'U'){
			int r = query(1,0,k2 - 1,Y[i],ST[0]);
		//	cerr << "U " << F[X[i]] << " -> " << G[Y[i]] << " -> " << F[r] << endl;
			printf("%d\n",F[X[i]] - F[r]);
			update(1,0,k1 - 1,r,X[i],Y[i],ST[1]);
		}
		else{
			int c = query(1,0,k1-1,X[i],ST[1]);
		//	cerr << "L " << F[X[i]] << " -> " << G[c] << endl;
			printf("%d\n",G[Y[i]] - G[c]);
			update(1,0,k2 - 1,c,Y[i],X[i],ST[0]);
		}
		S.insert(X[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define inf 1e9

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n >> q;
    set <pair <int,int>> dx,dy;
    while(q--){
        int x,y;
        char d;
        cin >> x >> y >> d;
        if(d=='L'){
            auto nxd=dy.upper_bound({x,inf});
            auto nyl=dx.lower_bound({y,0});
            if(nyl==dx.end()){
                if(nxd==dy.begin()){
                    cout << x << endl;
                    dx.insert({y,x});
                }
                else{
                    cout << x-(prev(nxd)->fi) << endl;
                    dx.insert({y,x-(prev(nxd)->fi)});
                }
            }
            else{
                if(nyl->fi == y){
                    cout << 0 << endl;
                }
                else{
                    if(nxd==dy.begin() || prev(nxd)->fi <= (n+1-(nyl->fi))){
                        cout << (nyl->fi)-y+(nyl->se) << endl;
                        dx.insert({y,(nyl->fi)-y+(nyl->se)});
                    }
                    else{
                        cout << x-(prev(nxd)->fi) << endl;
                        dx.insert({y,x-(prev(nxd)->fi)});
                    }
                }
            }
        }
        else{
            auto nyl = dx.upper_bound({y,inf});
            auto nxd = dy.lower_bound({x,0});
            if(nxd==dy.end()){
                if(nyl==dx.begin()){
                    cout << y << endl;
                    dy.insert({x,y});
                }
                else{
                    cout << y-(prev(nyl)->fi) << endl;
                    dx.insert({x,y-(prev(nyl)->fi)});
                }
            }
            else{
                if(nxd->fi == x){
                    cout << 0 << endl;
                }
                else{
                    if(nyl==dx.begin() || (prev(nyl))->fi <= (n+1-(nxd->fi))){
                        cout << (nxd->fi)-x+(nxd->se) << endl;
                        dx.insert({x,(nxd->fi)-x+(nxd->se)});
                    }
                    else{
                        cout << y-(prev(nyl)->fi) << endl;
                        dx.insert({x,y-(prev(nyl)->fi)});
                    }
                }
            }

        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second
#define inf 1e9

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n >> q;
    set <pair <int,int>> dx,dy;
    while(q--){
        int x,y;
        char d;
        cin >> x >> y >> d;
        if(d=='L'){
            auto nxd=dy.upper_bound({x,inf});
            auto nyl=dx.lower_bound({y,0});
            if(nyl==dx.end()){
                if(nxd==dy.begin()){
                    cout << x << endl;
                    dx.insert({y,x});
                }
                else{
                    cout << x-(prev(nxd)->fi) << endl;
                    dx.insert({y,x-(prev(nxd)->fi)});
                }
            }
            else{
                if(nyl->fi == y){
                    cout << 0 << endl;
                }
                else{
                    if(nxd==dy.begin() || prev(nxd)->fi <= (n+1-(nyl->fi))){
                        cout << (nyl->fi)-y+(nyl->se) << endl;
                        dx.insert({y,(nyl->fi)-y+(nyl->se)});
                    }
                    else{
                        cout << x-(prev(nxd)->fi) << endl;
                        dx.insert({y,x-(prev(nxd)->fi)});
                    }
                }
            }
        }
        else{
            auto nyl = dx.upper_bound({y,inf});
            auto nxd = dy.lower_bound({x,0});
            if(nxd==dy.end()){
                if(nyl==dx.begin()){
                    cout << y << endl;
                    dy.insert({x,y});
                }
                else{
                    cout << y-(prev(nyl)->fi) << endl;
                    dy.insert({x,y-(prev(nyl)->fi)});
                }
            }
            else{
                if(nxd->fi == x){
                    cout << 0 << endl;
                }
                else{
                    if(nyl==dx.begin() || (prev(nyl))->fi <= (n+1-(nxd->fi))){
                        cout << (nxd->fi)-x+(nxd->se) << endl;
                        dy.insert({x,(nxd->fi)-x+(nxd->se)});
                    }
                    else{
                        cout << y-(prev(nyl)->fi) << endl;
                        dy.insert({x,y-(prev(nyl)->fi)});
                    }
                }
            }

        }
    }
    return 0;
}


#include <bits/stdc++.h>
#define fi first
#define se second

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin >> n >> q;
    set <pair <int,int>> dx,dy;
    while(q--){
        int x,y;
        char d;
        cin >> x >> y >> d;
        if(d=='L'){
            auto nxd=dy.upper_bound({x,0});
            auto nyl=dx.lower_bound({y,0});
            if(nyl==dx.end()){
                if(nxd==dy.begin()){
                    cout << x << endl;
                    dx.insert({y,x});
                }
                else{
                    cout << x-(prev(nxd)->fi) << endl;
                    dx.insert({y,x-(prev(nxd)->fi)});
                }
            }
            else{
                if(nyl->fi == y){
                    cout << 0 << endl;
                }
                else{
                    if(nxd==dy.begin() || prev(nxd)->fi <= (n+1-(nyl->fi))){
                        cout << (nyl->fi)-y+(nyl->se) << endl;
                        dx.insert({y,(nyl->fi)-y+(nyl->se)});
                    }
                    else{
                        cout << x-(prev(nxd)->fi) << endl;
                        dx.insert({y,x-(prev(nxd)->fi)});
                    }
                }
            }
        }
        else{
            auto nyl = dx.upper_bound({y,0});
            auto nxd = dy.lower_bound({x,0});
            if(nxd==dy.end()){
                if(nyl==dx.begin()){
                    cout << y << endl;
                    dy.insert({x,y});
                }
                else{
                    cout << y-(prev(nyl)->fi) << endl;
                    dx.insert({x,y-(prev(nyl)->fi)});
                }
            }
            else{
                if(nxd->fi == x){
                    cout << 0 << endl;
                }
                else{
                    if(nyl==dx.begin() || (prev(nyl))->fi <= (n+1-(nxd->fi))){
                        cout << (nxd->fi)-x+(nxd->se) << endl;
                        dx.insert({x,(nxd->fi)-x+(nxd->se)});
                    }
                    else{
                        cout << y-(prev(nyl)->fi) << endl;
                        dx.insert({x,y-(prev(nyl)->fi)});
                    }
                }
            }

        }
    }
    return 0;
}


#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define N 200007
#define M (1<<19)

int n, m, q;

int load[2][2*M];
int x[N];
int y[N];
char t[N];

VI p;

void insert(int i, int a, int b, int v)
{
	a = lower_bound(ALL(p), a)-p.begin();
	b = upper_bound(ALL(p), b)-p.begin()-1;

	if(a>b)
		return;

	a += M;
	b += M;

	load[i][a] = max(load[i][a], v);
	load[i][b] = max(load[i][b], v);

	while(a<b-1)
	{
		if(a%2==0)
			load[i][a+1] = max(load[i][a+1], v);

		if(b%2==1)
			load[i][b-1] = max(load[i][b-1], v);

		a /= 2;
		b /= 2;
	}
}

int query(int i, int a)
{
	a = lower_bound(ALL(p), a)-p.begin();

	int res = 0;

	a += M;

	while(a>=1)
	{
		res = max(res, load[i][a]);
		a /= 2;
	}

	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> q;

	for(int i = 1; i <= q; ++i)
	{
		cin >> x[i] >> y[i] >> t[i];
		p.pb(x[i]);
		p.pb(y[i]);
	}

	sort(ALL(p));
	p.erase(unique(ALL(p)), p.end());

	for(int i = 1; i <= q; ++i)
	{
		if(t[i]=='U')
		{
			int g = query(0, x[i]);
			cout << y[i]-g << endl;
			insert(1, g+1, y[i], x[i]);
			insert(0, x[i], x[i], y[i]);
		}
		else
		{
			int g = query(1, y[i]);
			cout << x[i]-g << endl;
			insert(0, g+1, x[i], y[i]);
			insert(1, y[i], y[i], x[i]);
		}
	}
}


#include <bits/stdc++.h>
#include <unistd.h>
#define ll long long
#define ull unsigned long long
#define inf 1000000007
#define INF 1000000000000000007LL
#define VI vector<int>
#define VPII vector<pair<int, int> >
#define VLL vector<ll>
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
using namespace std;

#define N 200007
#define M (1<<19)

int n, m, q;

int load[2][2*M];
int x[N];
int y[N];
char t[N];

VI p;

void insert(int i, int a, int b, int v)
{
	a = lower_bound(ALL(p), a)-p.begin();
	b = upper_bound(ALL(p), b)-p.begin()-1;

	if(a>b)
		return;

	a += M;
	b += M;

	load[i][a] = max(load[i][a], v);
	load[i][b] = max(load[i][b], v);

	while(a<b-1)
	{
		if(a%2==0)
			load[i][a+1] = max(load[i][a+1], v);

		if(b%2==1)
			load[i][b-1] = max(load[i][b-1], v);

		a /= 2;
		b /= 2;
	}
}

int query(int i, int a)
{
	a = lower_bound(ALL(p), a)-p.begin();

	int res = 0;

	a += M;

	while(a>=1)
	{
		res = max(res, load[i][a]);
		a /= 2;
	}

	return res;
}

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

	cin >> n >> q;

	for(int i = 1; i <= q; ++i)
	{
		cin >> x[i] >> y[i] >> t[i];
		p.pb(x[i]);
		p.pb(y[i]);
	}

	sort(ALL(p));
	p.erase(unique(ALL(p)), p.end());

	for(int i = 1; i <= q; ++i)
	{
		if(t[i]=='U')
		{
			int g = query(0, x[i]);
			cout << y[i]-g << endl;
			insert(1, g+1, y[i], x[i]);
		}
		else
		{
			int g = query(1, y[i]);
			cout << x[i]-g << endl;
			insert(0, g+1, x[i], y[i]);
		}
	}
}


#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

template <class T>
class segment_tree {
private:
    static const T def = -1;

    struct node {
        T value;
        node* left;
        node* right;

        node(T value = def) : value(value), left(0), right(0) {}

        ~node() {
            delete left;
            delete right;
        }
    };

    static T node_value(node* t) {
        return t ? t->value : T();
    }

    static void node_add(node*& t, int p, T value, int tl, int tr) {
        if (t == nullptr) {
            t = new node{def};
        }
        if (tl + 1 == tr) {
            t->value = value;
            return;
        }
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            node_add(t->left, p, value, tl, tm);
        } else {
            node_add(t->right, p, value, tm, tr);
        }
        t->value = std::max(node_value(t->left), node_value(t->right));
    }

    static int node_leftmost_ge(node* t, T value, int l, int r, int tl, int tr) {
        if (l >= r) return tr;
        if (t == nullptr) return tr;
        if (tl + 1 == tr) {
            if (node_value(t) >= value) {
                return tl;
            } else {
                return tr;
            }
        }
        int tm = tl + (tr - tl) / 2;
        int lans = node_leftmost_ge(t->left, value, l, std::min(tm, r), tl, tm);
        if (lans != tm) {
            return lans;
        }
        return node_leftmost_ge(t->right, value, std::max(l, tm), r, tm, tr);
    }

    static int node_get(node* t, int p, int tl, int tr) {
        if (t == nullptr) return 0;
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            return node_get(t->left, p, tl, tm);
        } else {
            return node_get(t->left, p, tm, tr);
        }
    }

public:

    segment_tree(int max_value) {
        m_max_value = max_value;
        m_root = nullptr;
    }

    ~segment_tree() {
        delete m_root;
    }

    void add(int p, T value) {
        return node_add(m_root, p, value, 0, m_max_value);
    }

    int leftmost_ge(int l, int r, T value) {
        return node_leftmost_ge(m_root, value, l, r, 0, m_max_value);
    }

private:

    int m_max_value;
    node* m_root;
};

int main() {
    int n, q;
    cin >> n >> q;

    std::unordered_set<int> hor, ver;
    segment_tree<int> hort(n);
    segment_tree<int> vert(n);

    while (q--) {
        int x, y; cin >> x >> y;
        x = n - x;
        y = n - y;
        char c; cin >> std::skipws >> c;
        if (c == 'U') {
            if (ver.find(x) != ver.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = hort.leftmost_ge(y, n, x);
            if (h > y) {
                vert.add(x, h - 1);
                ver.insert(x);
            }
            cout << h - y << endl;
        } else {
            if (hor.find(y) != hor.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = vert.leftmost_ge(x, n, y);
            if (h > x) {
                hort.add(y, h - 1);
                hor.insert(y);
            }
            cout << h - x << endl;
        }
    }
}


#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

template <class T>
class segment_tree {
private:
    static const T def = -1;

    struct node {
        T value;
        node* left;
        node* right;

        node(T value = def) : value(value), left(0), right(0) {}

        ~node() {
            delete left;
            delete right;
        }
    };

    static T node_value(node* t) {
        return t ? t->value : T();
    }

    static void node_add(node*& t, int p, T value, int tl, int tr) {
        if (t == nullptr) {
            t = new node{def};
        }
        if (tl + 1 == tr) {
            t->value = value;
            return;
        }
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            node_add(t->left, p, value, tl, tm);
        } else {
            node_add(t->right, p, value, tm, tr);
        }
        t->value = std::max(node_value(t->left), node_value(t->right));
    }

    static int node_leftmost_ge(node* t, T value, int l, int r, int tl, int tr) {
        if (l >= r) return tr;
        if (t == nullptr) t = new node{def};
        if (tl + 1 == tr) {
            if (node_value(t) >= value) {
                return tl;
            } else {
                return tr;
            }
        }
        int tm = tl + (tr - tl) / 2;
        int lans = node_leftmost_ge(t->left, value, l, std::min(tm, r), tl, tm);
        if (lans != tm) {
            return lans;
        }
        return node_leftmost_ge(t->right, value, std::max(l, tm), r, tm, tr);
    }

    static int node_get(node* t, int p, int tl, int tr) {
        if (t == nullptr) return 0;
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            return node_get(t->left, p, tl, tm);
        } else {
            return node_get(t->left, p, tm, tr);
        }
    }

public:

    segment_tree(int max_value) {
        m_max_value = max_value;
        m_root = nullptr;
    }

    ~segment_tree() {
        delete m_root;
    }

    void add(int p, T value) {
        return node_add(m_root, p, value, 0, m_max_value);
    }

    int leftmost_ge(int l, int r, T value) {
        return node_leftmost_ge(m_root, value, l, r, 0, m_max_value);
    }

private:

    int m_max_value;
    node* m_root;
};

int main() {
    int n, q;
    cin >> n >> q;

    std::unordered_set<int> hor, ver;
    segment_tree<int> hort(n);
    segment_tree<int> vert(n);

    while (q--) {
        int x, y; cin >> x >> y;
        x = n - x;
        y = n - y;
        char c; cin >> std::skipws >> c;
        if (c == 'U') {
            cerr << "U ";
            if (ver.find(x) != ver.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = hort.leftmost_ge(y, n, x);
            cerr << h << ' ';
            if (h > y) {
                vert.add(x, h - 1);
                ver.insert(x);
            }
            cout << h - y << endl;
        } else {
            cerr << "L ";
            if (hor.find(y) != hor.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = vert.leftmost_ge(x, n, y);
            if (h > x) {
                hort.add(y, h - 1);
                hor.insert(y);
            }
            cout << h - x << endl;
        }
    }
}


#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

template <class T>
class segment_tree {
private:
    static const T def = -1;

    struct node {
        T value;
        node* left;
        node* right;

        node(T value = def) : value(value), left(0), right(0) {}

        ~node() {
            delete left;
            delete right;
        }
    };

    static T node_value(node* t) {
        return t ? t->value : def;
    }

    static void node_add(node*& t, int p, T value, int tl, int tr) {
        if (t == nullptr) {
            t = new node{def};
        }
        if (tl + 1 == tr) {
            t->value = value;
            return;
        }
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            node_add(t->left, p, value, tl, tm);
        } else {
            node_add(t->right, p, value, tm, tr);
        }
        t->value = std::max(node_value(t->left), node_value(t->right));
    }

    static int node_leftmost_ge(node* t, T value, int l, int r, int tl, int tr) {
        if (l >= r) return tr;
        if (node_value(t) < value) return tr;
        if (tl + 1 == tr) {
            if (node_value(t) >= value) {
                return tl;
            } else {
                return tr;
            }
        }
        int tm = tl + (tr - tl) / 2;
        int lans = node_leftmost_ge(t->left, value, l, std::min(tm, r), tl, tm);
        if (lans != tm) {
            return lans;
        }
        return node_leftmost_ge(t->right, value, std::max(l, tm), r, tm, tr);
    }

    static int node_get(node* t, int p, int tl, int tr) {
        if (t == nullptr) return 0;
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            return node_get(t->left, p, tl, tm);
        } else {
            return node_get(t->left, p, tm, tr);
        }
    }

public:

    segment_tree(int max_value) {
        m_max_value = max_value;
        m_root = nullptr;
    }

    /* ~segment_tree() { */
    /*     delete m_root; */
    /* } */

    void add(int p, T value) {
        return node_add(m_root, p, value, 0, m_max_value);
    }

    int leftmost_ge(int l, int r, T value) {
        return node_leftmost_ge(m_root, value, l, r, 0, m_max_value);
    }

private:

    int m_max_value;
    node* m_root;
};

int main() {
    int n, q;
    cin >> n >> q;

    std::unordered_set<int> hor, ver;
    hor.max_load_factor(0.75);
    hor.reserve(16);
    ver.max_load_factor(0.75);
    ver.reserve(16);
    segment_tree<int> hort(n);
    segment_tree<int> vert(n);

    while (q--) {
        int x, y; cin >> x >> y;
        x = n - x;
        y = n - y;
        char c; cin >> std::skipws >> c;
        if (c == 'U') {
            if (ver.find(x) != ver.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = hort.leftmost_ge(y, n, x);
            if (h > y) {
                vert.add(x, h - 1);
                ver.insert(x);
            }
            cout << h - y << endl;
        } else {
            if (hor.find(y) != hor.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = vert.leftmost_ge(x, n, y);
            if (h > x) {
                hort.add(y, h - 1);
                hor.insert(y);
            }
            cout << h - x << endl;
        }
    }
}


#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

template <class T>
class segment_tree {
private:
    static const T def = -1;

    struct node {
        T value;
        node* left;
        node* right;

        node(T value = def) : value(value), left(0), right(0) {}

        ~node() {
            delete left;
            delete right;
        }
    };

    static T node_value(node* t) {
        return t ? t->value : T();
    }

    static void node_add(node*& t, int p, T value, int tl, int tr) {
        if (t == nullptr) {
            t = new node{def};
        }
        if (tl + 1 == tr) {
            t->value = value;
            return;
        }
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            node_add(t->left, p, value, tl, tm);
        } else {
            node_add(t->right, p, value, tm, tr);
        }
        t->value = std::max(node_value(t->left), node_value(t->right));
    }

    static int node_leftmost_ge(node* t, T value, int l, int r, int tl, int tr) {
        if (l >= r) return tr;
        if (t == nullptr) return tr;
        if (tl + 1 == tr) {
            if (node_value(t) >= value) {
                return tl;
            } else {
                return tr;
            }
        }
        int tm = tl + (tr - tl) / 2;
        int lans = node_leftmost_ge(t->left, value, l, std::min(tm, r), tl, tm);
        if (lans != tm) {
            return lans;
        }
        return node_leftmost_ge(t->right, value, std::max(l, tm), r, tm, tr);
    }

    static int node_get(node* t, int p, int tl, int tr) {
        if (t == nullptr) return 0;
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            return node_get(t->left, p, tl, tm);
        } else {
            return node_get(t->left, p, tm, tr);
        }
    }

public:

    segment_tree(int max_value) {
        m_max_value = max_value;
        m_root = nullptr;
    }

    /* ~segment_tree() { */
    /*     delete m_root; */
    /* } */

    void add(int p, T value) {
        return node_add(m_root, p, value, 0, m_max_value);
    }

    int leftmost_ge(int l, int r, T value) {
        return node_leftmost_ge(m_root, value, l, r, 0, m_max_value);
    }

private:

    int m_max_value;
    node* m_root;
};

int main() {
    int n, q;
    cin >> n >> q;

    std::unordered_set<int> hor, ver;
    hor.max_load_factor(0.75);
    hor.reserve(16);
    ver.max_load_factor(0.75);
    ver.reserve(16);
    segment_tree<int> hort(n);
    segment_tree<int> vert(n);

    while (q--) {
        int x, y; cin >> x >> y;
        x = n - x;
        y = n - y;
        char c; cin >> std::skipws >> c;
        if (c == 'U') {
            if (ver.find(x) != ver.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = hort.leftmost_ge(y, n, x);
            if (h > y) {
                vert.add(x, h - 1);
                ver.insert(x);
            }
            cout << h - y << endl;
        } else {
            if (hor.find(y) != hor.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = vert.leftmost_ge(x, n, y);
            if (h > x) {
                hort.add(y, h - 1);
                hor.insert(y);
            }
            cout << h - x << endl;
        }
    }
}


#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

namespace chrono = std::chrono;
using namespace std::literals;

[[gnu::constructor]]
void fast_iostream() {
    std::ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
}

template <class T>
class segment_tree {
private:
    static const T def = -1;

    struct node {
        T value;
        node* left;
        node* right;

        node(T value = def) : value(value), left(0), right(0) {}

        ~node() {
            delete left;
            delete right;
        }
    };

    static T node_value(node* t) {
        return t ? t->value : def;
    }

    static void node_add(node*& t, int p, T value, int tl, int tr) {
        if (t == nullptr) {
            t = new node{def};
        }
        if (tl + 1 == tr) {
            t->value = value;
            return;
        }
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            node_add(t->left, p, value, tl, tm);
        } else {
            node_add(t->right, p, value, tm, tr);
        }
        t->value = std::max(node_value(t->left), node_value(t->right));
    }

    static int node_leftmost_ge(node* t, T value, int l, int r, int tl, int tr) {
        if (l >= r) return tr;
        if (node_value(t) < value) return tr;
        if (tl + 1 == tr) {
            if (node_value(t) >= value) {
                return tl;
            } else {
                return tr;
            }
        }
        int tm = tl + (tr - tl) / 2;
        int lans = node_leftmost_ge(t->left, value, l, std::min(tm, r), tl, tm);
        if (lans != tm) {
            return lans;
        }
        return node_leftmost_ge(t->right, value, std::max(l, tm), r, tm, tr);
    }

    static int node_get(node* t, int p, int tl, int tr) {
        if (t == nullptr) return 0;
        int tm = tl + (tr - tl) / 2;
        if (p < tm) {
            return node_get(t->left, p, tl, tm);
        } else {
            return node_get(t->left, p, tm, tr);
        }
    }

public:

    segment_tree(int max_value) {
        m_max_value = max_value;
        m_root = nullptr;
    }

    ~segment_tree() {
        delete m_root;
    }

    void add(int p, T value) {
        return node_add(m_root, p, value, 0, m_max_value);
    }

    int leftmost_ge(int l, int r, T value) {
        return node_leftmost_ge(m_root, value, l, r, 0, m_max_value);
    }

private:

    int m_max_value;
    node* m_root;
};

int main() {
    int n, q;
    cin >> n >> q;

    std::unordered_set<int> hor, ver;
    hor.max_load_factor(0.75);
    hor.reserve(16);
    ver.max_load_factor(0.75);
    ver.reserve(16);
    segment_tree<int> hort(n);
    segment_tree<int> vert(n);

    while (q--) {
        int x, y; cin >> x >> y;
        x = n - x;
        y = n - y;
        char c; cin >> std::skipws >> c;
        if (c == 'U') {
            if (ver.find(x) != ver.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = hort.leftmost_ge(y, n, x);
            if (h > y) {
                vert.add(x, h - 1);
                ver.insert(x);
            }
            cout << h - y << endl;
        } else {
            if (hor.find(y) != hor.end()) {
                cout << 0 << endl;
                continue;
            }
            int h = vert.leftmost_ge(x, n, y);
            if (h > x) {
                hort.add(y, h - 1);
                hor.insert(y);
            }
            cout << h - x << endl;
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "555C"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

int n,m;
map<int,int> mp;

struct node{
    int v,b;
    node *l, *r;
};

void init(node *&s){
    if(!s){
        s=new node(); s->l=s->r=nullptr; s->v=s->b=0;
    }
}

struct CTDL{
    void push(node *&s){
        if(!s->b) return;
        init(s->l); init(s->r);
        s->l->v=max(s->l->v,s->b);
        s->r->v=max(s->r->v,s->b);
        s->l->b=max(s->l->b,s->b);
        s->r->b=max(s->r->b,s->b);
        s->b=0;
    }
    void upd(node *&s,int l,int r,int u,int v,int x){
        if(u>v) return;
        init(s);
        if(l>v||u>r) return;
        if(u<=l&&r<=v){
            s->v=max(s->v,x);
            s->b=max(s->b,x); return;
        }
        push(s);
        int m=(l+r)/2;
        upd(s->l,l,m,u,v,x); upd(s->r,m+1,r,u,v,x);
        s->v=max(s->l->v,s->r->v);
    }
    int que(node *&s,int l,int r,int i){
        if(l>i||i>r||!s) return 0;
        if(l==r) return s->v;
        push(s);
        int m=(l+r)/2;
        return max(que(s->l,l,m,i),que(s->r,m+1,r,i));
    }
}H,V;
main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    n=in,m=in;
    node *rH=nullptr;
    node *rV=nullptr;
    forinc(i,1,m){
        int y=in,x=in; char ch; while(!isupper(ch=getchar()));
        if(mp[x]){
            cout<<"0\n";
            continue;
        }
        mp[x]=1;
        if(ch=='U'){
            int bar=H.que(rH,1,n,y);
            cout<<x-bar<<"\n";
            V.upd(rV,1,n,bar+1,x,y);
        } else{
            int bar=V.que(rV,1,n,x);
            cout<<y-bar<<"\n";
            H.upd(rH,1,n,bar+1,y,x);
        }
    }
}


#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "555C"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

int n,m;

struct node{
    int v,b;
    node *l, *r;
};

void init(node *&s){
    if(!s){
        s=new node(); s->l=s->r=nullptr; s->v=s->b=0;
    }
}

struct CTDL{
    void push(node *&s){
        if(!s->b) return;
        init(s->l); init(s->r);
        s->l->v=max(s->l->v,s->b);
        s->r->v=max(s->r->v,s->b);
        s->l->b=max(s->l->b,s->b);
        s->r->b=max(s->r->b,s->b);
        s->b=0;
    }
    void upd(node *&s,int l,int r,int u,int v,int x){
        if(u>v) return;
        init(s);
        if(l>v||u>r) return;
        if(u<=l&&r<=v){
            s->v=max(s->v,x);
            s->b=max(s->b,x); return;
        }
        push(s);
        int m=(l+r)/2;
        upd(s->l,l,m,u,v,x); upd(s->r,m+1,r,u,v,x);
        s->v=max(s->l->v,s->r->v);
    }
    int que(node *&s,int l,int r,int i){
        if(l>i||i>r||!s) return 0;
        if(l==r) return s->v;
        push(s);
        int m=(l+r)/2;
        return max(que(s->l,l,m,i),que(s->r,m+1,r,i));
    }
}H,V;
main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    n=in,m=in;
    node *rH=nullptr;
    node *rV=nullptr;
    forinc(i,1,m){
        int y=in,x=in; char ch; while(!isupper(ch=getchar()));
        if(ch=='U'){
            int bar=H.que(rH,1,n,y);
            cout<<x-bar<<"\n";
            V.upd(rV,1,n,bar+1,x,y);
        } else{
            int bar=V.que(rV,1,n,x);
            cout<<y-bar<<"\n";
            H.upd(rH,1,n,bar+1,y,x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define xx first
#define yy second
#define mx 100001
map<int,int> lef,up;
int n;
int updup(int x,int y)
{
	if(lef.find(y)!=lef.end() || up.find(x)!=up.end())
		return 0;
	auto it=lef.lower_bound(y);
	it--;
	auto ita=up.lower_bound(x);
	if((ita->first)>n+1-(it->first))
	{
		up[x]=it->first;
		return y-(it->first);
	}
	up[x]=ita->second;
	return y-up[x];
}
int updleft(int x,int y)
{
	if(lef.find(y)!=lef.end() || up.find(x)!=up.end())
		return 0;
	auto it=up.lower_bound(x);
	it--;
	auto ita=lef.lower_bound(y);
	if((ita->first)>n+1-(it->first))
	{
		lef[y]=it->first;
		return x-(it->first);
	}
	lef[y]=ita->second;
	return x-lef[y];
}
int main()
{
	int q;cin>>n>>q;
	up[0]=n+1;
	up[n+1]=0;
	lef[0]=n+1;
	lef[n+1]=0;
	ios_base::sync_with_stdio(false);
	while(q--)
	{
		int x,y;
		char c;cin>>x>>y>>c;
		if(c=='U')
			pd(updup(x,y));
		else
			pd(updleft(x,y));
		nl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define sd(a) scanf("%d", &a)
#define sd2(a,b) scanf("%d%d", &a, &b)
#define sd3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define sld(a) scanf("%lld", &a)
#define sld2(a,b) scanf("%lld%lld", &a, &b)
#define sld3(a, b, c) scanf("%lld%lld%lld", &a, &b, &c)
#define pd(a) printf("%d", a)
#define pld(a) printf("%lld", a)
#define sp printf(" ")
#define nl printf("\n")
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
#define clr(a, val) memset((a), (val), sizeof(a))
#define pb push_back
#define endl "\n"
#define mp(a, b) make_pair(a, b)
#define pii pair<int, int>
#define xx first
#define yy second
#define mx 100001
map<int,int> lef,up;
int n;
int updup(int x,int y)
{
	if(lef.find(y)!=lef.end() || up.find(x)!=up.end())
		return 0;
	auto it=lef.lower_bound(y);
	it--;
	auto ita=up.lower_bound(x);
	if((ita->first)>n+1-(it->first))
	{
		up[x]=it->first;
		return y-(it->first);
	}
	up[x]=ita->second;
	return y-up[x];
}
int updleft(int x,int y)
{
	if(lef.find(y)!=lef.end() || up.find(x)!=up.end())
		return 0;
	auto it=up.lower_bound(x);
	it--;
	auto ita=lef.lower_bound(y);
	if((ita->first)>n+1-(it->first))
	{
		lef[y]=it->first;
		return x-(it->first);
	}
	lef[y]=ita->second;
	return x-lef[y];
}
int main()
{
	ios_base::sync_with_stdio(false);
	int q;cin>>n>>q;
	up[0]=n+1;
	up[n+1]=0;
	lef[0]=n+1;
	lef[n+1]=0;
	while(q--)
	{
		int x,y;
		char c;cin>>x>>y>>c;
		if(c=='U')
			pd(updup(x,y));
		else
			pd(updleft(x,y));
		nl;
	}
}


#include <bits/stdc++.h>
using namespace std;

#define MP(a,b) make_pair(a,b)
typedef pair<int,int> pr;
typedef pair<bool,int> PR;
typedef map<pr,PR>::iterator ITER;

int n, q, ans;
map <pr, PR> M;

void getans(pr p, bool k)
{
	if(M.count(p)) ans = 0;
	else if(k == 1)
	{
		ITER I = M.upper_bound(p);
		pair<pr, PR> P = *I;
		if(P.second.first == 1)
			ans = P.second.second - P.first.second + p.second;
		else
			ans = p.second - P.first.second;
	}
	else
	{
		ITER I = M.upper_bound(p);
		pair<pr, PR> P = *(--I);
		if(P.second.first == 1)
			ans = P.first.second - p.second;
		else
			ans = P.second.second - p.second +  P.first.second;
	}
	M[p] = MP(k,ans);
	printf("%d\n", ans);
}

int main()
{
	scanf("%d%d", &n, &q);
	M[MP(0, n+1)] = MP(1, 0);
	M[MP(n+1, 0)] = MP(0, 0);

	for(int i = 0; i < q; ++ i)
	{
		int c, r; char s;
		scanf("%d %d %c",&c, &r, &s);
		if(s == 'U') getans(MP(c,r), 1);
		else getans(MP(c,r), 0);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MP(a,b) make_pair(a,b)
typedef pair<int,int> pr;
typedef pair<bool,int> PR;
typedef map<pr,PR>::iterator ITER;

int n, q, ans;
map <pr, PR> M;

void getans(pr p, bool k)
{
	if(M.count(p)) {printf("0\n"); return; }
	ITER I = M.upper_bound(p);
	if(k == 1)
	{
		pair<pr, PR> P = *I;
		if(P.second.first == 1)
			ans = P.second.second - P.first.second + p.second;
		else
			ans = p.second - P.first.second;
	}
	else
	{
		pair<pr, PR> P = *(--I);
		if(P.second.first == 1)
			ans = P.first.second - p.second;
		else
			ans = P.second.second - p.second +  P.first.second;
	}
	M[p] = MP(k,ans);
	printf("%d\n", ans);
}

int main()
{
	scanf("%d%d", &n, &q);
	M[MP(0, n+1)] = MP(1, 0);
	M[MP(n+1, 0)] = MP(0, 0);

	for(int i = 0; i < q; ++ i)
	{
		int c, r; char s;
		scanf("%d %d %c",&c, &r, &s);
		if(s == 'U') getans(MP(c,r), 1);
		else getans(MP(c,r), 0);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define MP(a,b) make_pair(a,b)
typedef pair<int,int> pr;
typedef pair<bool,int> PR;
typedef map<pr,PR>::iterator ITER;

int n, q, ans;
map <pr, PR> M;

void getans(pr p, bool k)
{
	if(M.count(p)) {printf("0\n"); return; }
	ITER I = M.upper_bound(p);
	if(k == 1)
	{
		pair<pr, PR> P = *I;
		printf("%d %d %d\n", P.first.first, P.first.second, P.second.second);
		if(P.second.first == 1)
			ans = P.second.second - P.first.second + p.second;
		else
			ans = p.second - P.first.second;
	}
	else
	{
		pair<pr, PR> P = *(--I);
		if(P.second.first == 1)
			ans = P.first.second - p.second;
		else
			ans = P.second.second - p.second +  P.first.second;
	}
	M[p] = MP(k,ans);
	printf("%d\n", ans);
}

int main()
{
	scanf("%d%d", &n, &q);
	M[MP(0, n+1)] = MP(1, 0);
	M[MP(n+1, 0)] = MP(0, 0);

	for(int i = 0; i < q; ++ i)
	{
		int c, r; char s;
		scanf("%d %d %c",&c, &r, &s);
		if(s == 'U') getans(MP(c,r), 1);
		else getans(MP(c,r), 0);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int n, q, ans;
set <int> L, U;

int main()
{
	scanf("%d%d", &n, &q);
	L.insert(0);
	U.insert(0);

	for(int i = 0; i < q; ++ i)
	{
		int c, r; char s;
		scanf("%d %d %c", &c, &r, &s);
		if(s == 'U')
		{
			set<int>::iterator I = upper_bound(L.begin(), L.end(), r);
			ans = r - *(--I);
			U.insert(c);
		}
		else
		{
			set<int>::iterator I = upper_bound(U.begin(), U.end(), c);
			ans = c - *(--I);
			L.insert(r);
		}
		printf("%d\n", ans);
	}

	return 0;
}


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=400000+10,maxn=2000000+10,inf=0x3f3f3f3f;

struct sgt{
    int ma[N<<2],lazy[N<<2];
    void pushdown(int rt)
    {
        if(lazy[rt])
        {
            ma[rt<<1]=max(ma[rt<<1],lazy[rt]);
            ma[rt<<1|1]=max(ma[rt<<1|1],lazy[rt]);
            lazy[rt<<1]=max(lazy[rt<<1],lazy[rt]);
            lazy[rt<<1|1]=max(lazy[rt<<1|1],lazy[rt]);
            lazy[rt]=0;
        }
    }
    void update(int L,int R,int v,int l,int r,int rt)
    {
        if(L<=l&&r<=R){ma[rt]=max(ma[rt],v);lazy[rt]=max(lazy[rt],v);return ;}
        pushdown(rt);
        int m=(l+r)>>1;
        if(L<=m)update(L,R,v,ls);
        if(m<R)update(L,R,v,rs);
        ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
    }
    int query(int L,int R,int l,int r,int rt)
    {
        if(L<=l&&r<=R)return ma[rt];
        pushdown(rt);
        int m=(l+r)>>1,ans=0;
        if(L<=m)ans=max(ans,query(L,R,ls));
        if(m<R)ans=max(ans,query(L,R,rs));
        return ans;
    }
}sg[2];
char s[10];
struct info{int x,y,op;}a[N];
int c[N],d;
int main()
{
    int n,q;scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%s",&a[i].x,&a[i].y,s);
        a[i].op=(s[0]=='U');
        c[d++]=a[i].x,c[d++]=a[i].y;
    }
    sort(c,c+d);d=unique(c,c+d)-c;
    for(int i=1;i<=q;i++)
    {
        int x=lower_bound(c,c+d,a[i].x)-c+1,y=lower_bound(c,c+d,a[i].y)-c+1;
        if(a[i].op==1)
        {
            int ma=sg[0].query(x,x,1,d,1);
            printf("%d\n",a[i].y-c[ma-1]);
            sg[1].update(ma,y,x,1,d,1);
        }
        else
        {
            int ma=sg[1].query(y,y,1,d,1);
            printf("%d\n",a[i].x-c[ma-1]);
            sg[0].update(ma,x,y,1,d,1);
        }
    }
    return 0;
}
/********************

********************/


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=400000+10,maxn=2000000+10,inf=0x3f3f3f3f;

struct sgt{
    int ma[N<<2],lazy[N<<2];
    void pushdown(int rt)
    {
        if(lazy[rt])
        {
            ma[rt<<1]=max(ma[rt<<1],lazy[rt]);
            ma[rt<<1|1]=max(ma[rt<<1|1],lazy[rt]);
            lazy[rt<<1]=max(lazy[rt<<1],lazy[rt]);
            lazy[rt<<1|1]=max(lazy[rt<<1|1],lazy[rt]);
            lazy[rt]=0;
        }
    }
    void update(int L,int R,int v,int l,int r,int rt)
    {
        if(L<=l&&r<=R){ma[rt]=max(ma[rt],v);lazy[rt]=max(lazy[rt],v);return ;}
        pushdown(rt);
        int m=(l+r)>>1;
        if(L<=m)update(L,R,v,ls);
        if(m<R)update(L,R,v,rs);
        ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
    }
    int query(int L,int R,int l,int r,int rt)
    {
        if(L<=l&&r<=R)return ma[rt];
        pushdown(rt);
        int m=(l+r)>>1,ans=0;
        if(L<=m)ans=max(ans,query(L,R,ls));
        if(m<R)ans=max(ans,query(L,R,rs));
        return ans;
    }
}sg[2];
char s[10];
struct info{int x,y,op;}a[N];
int c[N],d;
bool vis[N][2];
int main()
{
    int n,q;scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%s",&a[i].x,&a[i].y,s);
        a[i].op=(s[0]=='U');
        c[d++]=a[i].x,c[d++]=a[i].y;
    }
    sort(c,c+d);d=unique(c,c+d)-c;
    for(int i=1;i<=q;i++)
    {
        int x=lower_bound(c,c+d,a[i].x)-c+1,y=lower_bound(c,c+d,a[i].y)-c+1;
        if(a[i].op==1)
        {
            if(vis[x][0]){puts("0");continue;}
            vis[x][0]=1;
            int ma=sg[0].query(x,x,1,d,1);
            printf("%d\n",a[i].y-(ma>0?c[ma-1]:0));
            sg[1].update(ma==0?1:ma,y,x,1,d,1);
        }
        else
        {
            if(vis[y][1]){puts("0");continue;}
            vis[y][1]=1;
            int ma=sg[1].query(y,y,1,d,1);
            printf("%d\n",a[i].x-(ma>0?c[ma-1]:0));
            sg[0].update(ma==0?1:ma,x,y,1,d,1);
        }
    }
    return 0;
}
/********************

********************/


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=400000+10,maxn=2000000+10,inf=0x3f3f3f3f;

struct sgt{
    int ma[N<<2],lazy[N<<2];
    void pushdown(int rt)
    {
        if(lazy[rt])
        {
            ma[rt<<1]=max(ma[rt<<1],lazy[rt]);
            ma[rt<<1|1]=max(ma[rt<<1|1],lazy[rt]);
            lazy[rt<<1]=max(lazy[rt<<1],lazy[rt]);
            lazy[rt<<1|1]=max(lazy[rt<<1|1],lazy[rt]);
            lazy[rt]=0;
        }
    }
    void update(int L,int R,int v,int l,int r,int rt)
    {
        if(L<=l&&r<=R){ma[rt]=max(ma[rt],v);lazy[rt]=max(lazy[rt],v);return ;}
        pushdown(rt);
        int m=(l+r)>>1;
        if(L<=m)update(L,R,v,ls);
        if(m<R)update(L,R,v,rs);
        ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
    }
    int query(int L,int R,int l,int r,int rt)
    {
        if(L<=l&&r<=R)return ma[rt];
        pushdown(rt);
        int m=(l+r)>>1,ans=0;
        if(L<=m)ans=max(ans,query(L,R,ls));
        if(m<R)ans=max(ans,query(L,R,rs));
        return ans;
    }
}sg[2];
char s[10];
struct info{int x,y,op;}a[N];
int c[N],d;
int main()
{
    int n,q;scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%s",&a[i].x,&a[i].y,s);
        a[i].op=(s[0]=='U');
        c[d++]=a[i].x,c[d++]=a[i].y;
    }
    c[d++]=0;
    sort(c,c+d);d=unique(c,c+d)-c;
    for(int i=1;i<=q;i++)
    {
        int x=lower_bound(c,c+d,a[i].x)-c+1,y=lower_bound(c,c+d,a[i].y)-c+1;
        if(a[i].op==1)
        {
            int ma=sg[0].query(x,x,1,d,1);
            printf("%d\n",a[i].y-c[ma-1]);
            sg[1].update(ma,y,x,1,d,1);
        }
        else
        {
            int ma=sg[1].query(y,y,1,d,1);
            printf("%d\n",a[i].x-c[ma-1]);
            sg[0].update(ma,x,y,1,d,1);
        }
    }
    return 0;
}
/********************

********************/


//#pragma GCC optimize(2)
//#pragma GCC optimize(3)
//#pragma GCC optimize(4)
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
//#include <bits/extc++.h>
#define fi first
#define se second
#define db double
#define mp make_pair
#define pb push_back
#define mt make_tuple
//#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define ld long double
//#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define bpc __builtin_popcount
#define base 1000000000000000000ll
#define fin freopen("a.txt","r",stdin)
#define fout freopen("a.txt","w",stdout)
#define fio ios::sync_with_stdio(false);cin.tie(0)
#define mr mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline void sub(ll &a,ll b){a-=b;if(a<0)a+=mod;}
inline void add(ll &a,ll b){a+=b;if(a>=mod)a-=mod;}
template<typename T>inline T const& MAX(T const &a,T const &b){return a>b?a:b;}
template<typename T>inline T const& MIN(T const &a,T const &b){return a<b?a:b;}
inline ll mul(ll a,ll b,ll c){return (a*b-(ll)((ld)a*b/c)*c+c)%c;}
inline ll qp(ll a,ll b){ll ans=1;while(b){if(b&1)ans=ans*a%mod;a=a*a%mod,b>>=1;}return ans;}
inline ll qp(ll a,ll b,ll c){ll ans=1;while(b){if(b&1)ans=mul(ans,a,c);a=mul(a,a,c),b>>=1;}return ans;}

using namespace std;
//using namespace __gnu_pbds;

const ld pi = acos(-1);
const ull ba=233;
const db eps=1e-5;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int N=400000+10,maxn=2000000+10,inf=0x3f3f3f3f;

struct sgt{
    int ma[N<<2],lazy[N<<2];
    void pushdown(int rt)
    {
        if(lazy[rt])
        {
            ma[rt<<1]=max(ma[rt<<1],lazy[rt]);
            ma[rt<<1|1]=max(ma[rt<<1|1],lazy[rt]);
            lazy[rt<<1]=max(lazy[rt<<1],lazy[rt]);
            lazy[rt<<1|1]=max(lazy[rt<<1|1],lazy[rt]);
            lazy[rt]=0;
        }
    }
    void update(int L,int R,int v,int l,int r,int rt)
    {
        if(L<=l&&r<=R){ma[rt]=max(ma[rt],v);lazy[rt]=max(lazy[rt],v);return ;}
        pushdown(rt);
        int m=(l+r)>>1;
        if(L<=m)update(L,R,v,ls);
        if(m<R)update(L,R,v,rs);
        ma[rt]=max(ma[rt<<1],ma[rt<<1|1]);
    }
    int query(int L,int R,int l,int r,int rt)
    {
        if(L<=l&&r<=R)return ma[rt];
        pushdown(rt);
        int m=(l+r)>>1,ans=0;
        if(L<=m)ans=max(ans,query(L,R,ls));
        if(m<R)ans=max(ans,query(L,R,rs));
        return ans;
    }
}sg[2];
char s[10];
struct info{int x,y,op;}a[N];
int c[N],d;
int main()
{
    int n,q;scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%s",&a[i].x,&a[i].y,s);
        a[i].op=(s[0]=='U');
        c[d++]=a[i].x,c[d++]=a[i].y;
    }
    sort(c,c+d);d=unique(c,c+d)-c;
    for(int i=1;i<=q;i++)
    {
        int x=lower_bound(c,c+d,a[i].x)-c+1,y=lower_bound(c,c+d,a[i].y)-c+1;
        if(a[i].op==1)
        {
            int ma=sg[0].query(x,x,1,d,1);
            printf("%d\n",a[i].y-(ma>0?c[ma-1]:0));
            sg[1].update(ma,y,x,1,d,1);
        }
        else
        {
            int ma=sg[1].query(y,y,1,d,1);
            printf("%d\n",a[i].x-(ma>0?c[ma-1]:0));
            sg[0].update(ma,x,y,1,d,1);
        }
    }
    return 0;
}
/********************

********************/


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(ll p,ll q)
    {
        return max(p,q);
    }
    ll getValue(ll v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(ll v,ll x)
    {
        lazy[v]=max(x,lazy[v]);
    }

    // Constructors and utilities
    map<ll,ll> st,lazy,len;
    int n;
    inline int left(ll x)
    {
        return x*2;
    }
    inline int right(ll x)
    {
        return x*2+1;
    }
    inline int mid(ll l,ll r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
    }
    // Segtree functions
    void combine(ll v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(ll v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(ll v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(ll v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    int n,q;
    scanf("%d %d",&n,&q);
    LazySegmentTree highX(n+5),highY(n+5);
    map<int,int> done;
    map<int,set<int>> adjU,adjL;
    done[0]=done[n+1]=1;
    adjU[0].insert(n+1);
    adjL[0].insert(n+1);
    int x,y;
    char ch;

    forl(i,q)
    {
        scanf("%d %d %c",&x,&y,&ch);
        if(done[x])
        {
            cout<<0<<endl;
            continue;
        }
        done[x]=1;
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=n+1-rX;
            printf("%d\n",y-rY);
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=n+1-rY;
            printf("%d\n",x-rX);
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(ll p,ll q)
    {
        return max(p,q);
    }
    ll getValue(ll v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(ll v,ll x)
    {
        lazy[v]=max(x,lazy[v]);
    }

    // Constructors and utilities
    map<ll,ll> st,lazy,len;
    int n;
    inline int left(ll x)
    {
        return x*2;
    }
    inline int right(ll x)
    {
        return x*2+1;
    }
    inline int mid(ll l,ll r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
    }
    // Segtree functions
    void combine(ll v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(ll v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(ll v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(ll v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    fastio;
    int n,q;
    cin>>n>>q;
    LazySegmentTree highX(n+5),highY(n+5);
    map<int,int> done;
    map<int,set<int>> adjU,adjL;
    done[0]=done[n+1]=1;
    adjU[0].insert(n+1);
    adjL[0].insert(n+1);

    forl(i,q)
    {
        int x,y;
        char ch;
        cin>>x>>y>>ch;
        if(done[x])
        {
            cout<<0<<endl;
            continue;
        }
        done[x]=1;
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=n+1-rX;
            cout<<y-rY<<endl;
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=n+1-rY;
            cout<<x-rX<<endl;
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(ll p,ll q)
    {
        return max(p,q);
    }
    ll getValue(ll v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(ll v,ll x)
    {
        lazy[v]=max(x,lazy[v]);
    }

    // Constructors and utilities
    map<ll,ll> st,lazy,len;
    int n;
    inline int left(ll x)
    {
        return x*2;
    }
    inline int right(ll x)
    {
        return x*2+1;
    }
    inline int mid(ll l,ll r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
    }
    // Segtree functions
    void combine(ll v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(ll v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(ll v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(ll v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    fastio;
    int n,q;
    cin>>n>>q;
    LazySegmentTree highX(n+5),highY(n+5);
    map<int,int> done;
    map<int,set<int>> adjU,adjL;
    done[0]=done[n+1]=1;
    adjU[0].insert(n+1);
    adjL[0].insert(n+1);

    forl(i,q)
    {
        int x,y;
        char ch;
        cin>>x>>y>>ch;
        if(done[x])
        {
            cout<<0<<endl;
            done[x]=1;
            continue;
        }
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=n+1-rX;
            cout<<y-rY<<endl;
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=n+1-rY;
            cout<<x-rX<<endl;
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(int p,int q)
    {
        return max(p,q);
    }
    ll getValue(int v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(int v,int x)
    {
        lazy[v]=max(lazy[v],1ll*x);
    }

    // Constructors and utilities
    vl st,lazy,len;
    int n;
    inline int left(int x)
    {
        return x<<1;
    }
    inline int right(int x)
    {
        return (x<<1)|1;
    }
    inline int mid(int l,int r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
        st.assign(4*n,0);
        lazy.assign(4*n,lnull);
        len.resize(4*n);
        vl a(n,init);
        build(a,1,0,n-1);
    }
    LazySegmentTree(vl &a)
    {
        n=a.size();
        st.assign(4*n,0);
        lazy.assign(4*n,lnull);
        len.resize(4*n);
        build(a,1,0,n-1);
    }
    void build(vl &a,int v,int tl,int tr)
    {
        len[v]=tr-tl+1;
        if(tl==tr)
        {
            st[v]=a[tl];
            return;
        }
        int tm=mid(tl,tr);
        build(a,left(v),tl,tm);
        build(a,right(v),tm+1,tr);
        combine(v);
    }

    // Segtree functions
    void combine(int v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(int v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(int v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(int v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    int n,q;
    cin>>n>>q;
    vector<pair<ii,char>> Q(q);
    unordered_map<int,int> currX,currY;
    vector<set<int>> adjU(q+5),adjL(q+5);
    LazySegmentTree highX(q+5),highY(q+5);
    vi X,Y;
    X.pb(0);
    X.pb(n+1);
    Y.pb(0);
    Y.pb(n+1);
    forl(i,q)
    {
        cin>>Q[i].F.F>>Q[i].F.S>>Q[i].S;
        if(currX[Q[i].F.F]!=1)
            X.pb(Q[i].F.F);
        if(currY[Q[i].F.S]!=1)
            Y.pb(Q[i].F.S);
        currX[Q[i].F.F]=1;
        currY[Q[i].F.S]=1;
    }
    sort(all(X));
    sort(all(Y));
    forl(i,X.size())
        currX[X[i]]=i;
    forl(i,Y.size())
        currY[Y[i]]=i;
    // cout<<currX[n+1]<<endl;
    adjU[0].insert(currX[n+1]);
    adjL[0].insert(currY[n+1]);
    vi done(q+5,0);
    forl(i,q)
    {
        int XX=Q[i].F.F,YY=Q[i].F.S;
        int x=currX[XX];
        int y=currY[YY];
        char ch=Q[i].S;
        // cout<<x<<' '<<y<<' '<<ch<<endl;
        if(done[x])
        {
            cout<<0<<endl;
            continue;
        }
        done[x]=1;
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=currY[n+1-X[rX]];
            printf("%d\n",Y[y]-Y[rY]);
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=currX[n+1-Y[rY]];
            printf("%d\n",X[x]-X[rX]);
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(ll p,ll q)
    {
        return max(p,q);
    }
    ll getValue(ll v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(ll v,ll x)
    {
        lazy[v]=max(x,lazy[v]);
    }

    // Constructors and utilities
    unordered_map<ll,ll> st,lazy,len;
    int n;
    inline int left(ll x)
    {
        return x*2;
    }
    inline int right(ll x)
    {
        return x*2+1;
    }
    inline int mid(ll l,ll r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
    }
    // Segtree functions
    void combine(ll v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(ll v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(ll v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(ll v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    int n,q;
    scanf("%d %d",&n,&q);
    LazySegmentTree highX(n+5),highY(n+5);
    map<int,int> done;
    map<int,set<int>> adjU,adjL;
    done[0]=done[n+1]=1;
    adjU[0].insert(n+1);
    adjL[0].insert(n+1);
    int x,y;
    char ch;

    forl(i,q)
    {
        scanf("%d %d %c",&x,&y,&ch);
        if(done[x])
        {
            cout<<0<<endl;
            continue;
        }
        done[x]=1;
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=n+1-rX;
            printf("%d\n",y-rY);
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=n+1-rY;
            printf("%d\n",x-rX);
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
ll power(ll a,ll b, ll m=MOD)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
            res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
ll inverse(ll a,ll m=MOD)
{
    return power(a,m-2,m);
}
#define INFl 1e18
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<long long>
#define vvl vector<vl>
#define ii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define rforl(i,n)  for(int i=n-1;i>=0;i--)
#define rfore(i,n)  for(int i=n;i>=1;i--)
#define INF 1100000009
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define mp make_pair
#define pb push_back
#define print(x)    for(auto it=x.begin();it!=x.end();it++) printf("%d ",*it); printf("\n");
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<it->F<<' '<<it->S<<'\n';
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
struct LazySegmentTree
{
    // Change these functions
    ll null=0,lnull=0,init=0;
    ll combine(ll p,ll q)
    {
        return max(p,q);
    }
    ll getValue(ll v)
    {
        if(lazy[v]!=lnull) return max(st[v],lazy[v]);
        return st[v];
    }
    void modifyLazy(ll v,ll x)
    {
        lazy[v]=max(x,lazy[v]);
    }

    // Constructors and utilities
    unordered_map<ll,ll> st,lazy,len;
    int n;
    inline int left(ll x)
    {
        return x*2;
    }
    inline int right(ll x)
    {
        return x*2+1;
    }
    inline int mid(ll l,ll r)
    {
        return (l+r)/2;
    }

    LazySegmentTree() {}
    LazySegmentTree(int N)
    {
        n=N;
    }
    // Segtree functions
    void combine(ll v)
    {
        st[v]=combine(getValue(left(v)),getValue(right(v)));
    }
    void push(ll v)
    {
        if(lazy[v]==lnull)    return;
        st[v]=getValue(v);
        modifyLazy(left(v),lazy[v]);
        modifyLazy(right(v),lazy[v]);
        lazy[v]=lnull;
    }

    void update(ll v,int tl,int tr,int l,int r,int x)
    {
        if(l>r) return;
        if(tl==l && tr==r)
        {
            modifyLazy(v,x);
            return;
        }
        push(v);
        int tm=mid(tl,tr);
        update(left(v),tl,tm,l,min(r,tm),x);
        update(right(v),tm+1,tr,max(l,tm+1),r,x);
        combine(v);
    }
    ll query(ll v,int tl,int tr,int l,int r)
    {
        if(l>r) return null;
        if(tl==l && tr==r)
            return getValue(v);
        push(v);
        int tm=mid(tl,tr);
        ll resl=query(left(v),tl,tm,l,min(r,tm));
        ll resr=query(right(v),tm+1,tr,max(l,tm+1),r);
        return combine(resl,resr);
    }

    // UI
    void update(int pos,int x)
    {
        update(1,0,n-1,pos,pos,x);
    }
    void update(int l,int r,int x)
    {
        update(1,0,n-1,l,r,x);
    }
    ll query(int l,int r)
    {
        return query(1,0,n-1,l,r);
    }
    ll query(int x)
    {
        return query(x,x);
    }
};
int main()
{
    int n,q;
    scanf("%d %d",&n,&q);
    LazySegmentTree highX(n+5),highY(n+5);
    unordered_map<int,int> done;
    unordered_map<int,set<int>> adjU,adjL;
    done[0]=done[n+1]=1;
    adjU[0].insert(n+1);
    adjL[0].insert(n+1);
    int x,y;
    char ch;

    forl(i,q)
    {
        scanf("%d %d %c",&x,&y,&ch);
        if(done[x])
        {
            cout<<0<<endl;
            continue;
        }
        done[x]=1;
        if(ch=='U')
        {
            int hX=highX.query(y);
            int rX=*adjU[hX].lower_bound(x);
            int rY=n+1-rX;
            printf("%d\n",y-rY);
            highX.update(rY,y,x);
            adjU[x].insert(rX);
            adjL[rY].insert(y);
        }
        else
        {
            int hY=highY.query(x);
            int rY=*adjL[hY].lower_bound(y);
            int rX=n+1-rY;
            printf("%d\n",x-rX);
            highY.update(rX,x,y);
            adjL[y].insert(rY);
            adjU[rX].insert(x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N = 400005;
struct ch{
    int x,y;
    char ty;
    ch(int xx,int yy,char tt){
        x=xx;
        y=yy;
        ty=tt;
    }
};
vector<ch> q;
map<int,int> mp;
int st[4*N][2],lazy[4*N][2];
void update(int ss,int se,int l,int r,int val,int i,int ty){
    if(lazy[i][ty]!=-1){
        st[i][ty]=max(st[i][ty],lazy[i][ty]);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],lazy[i][ty]);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],lazy[i][ty]);
        }
        lazy[i][ty]=-1;
    }
    if(ss>se || l>se || r < ss)
        return;
    if(l<=ss &&se<=r){
        st[i][ty]=max(st[i][ty],val);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],val);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],val);
        }
        return;
    }
    int mid=(ss+se)/2;
    update(ss,mid,l,r,val,2*i+1,ty);
    update(mid+1,se,l,r,val,2*i+2,ty);
    st[i][ty]=max(st[2*i+1][ty],st[2*i+2][ty]);
}
int query(int ss,int se,int l,int r,int i,int ty){
    if(lazy[i][ty]!=-1){
        st[i][ty]=max(st[i][ty],lazy[i][ty]);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],lazy[i][ty]);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],lazy[i][ty]);
        }
        lazy[i][ty]=-1;
    }
    if(ss>se || ss>r || se<l)
        return -1;
    if(l<=ss && se<=r){
        return st[i][ty];
    }
    int mid=(ss+se)/2;
    return max(query(ss,mid,l,r,2*i+1,ty),query(mid+1,se,l,r,2*i+2,ty));
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,i,m;
    cin>>n>>m;
    for(i=0;i<m;i++){
        int x,y;
        char ty;
        cin>>x>>y>>ty;
        mp[x-1];mp[y-1];
        q.push_back(ch(y-1,x-1,ty));
    }
    int cc=0;
    for(auto it : mp){
        mp[it.first] = cc++;
    }
    memset(st,-1,sizeof(st));
    memset(lazy,-1,sizeof(lazy));
    for(i=0;i<m;i++){
        int r,c,rm,cm,ans;
        r=q[i].x; c=q[i].y;
        if(q[i].ty == 'U'){
            rm=query(0,N-1,mp[c],mp[c],0,0);
            ans=max(0,r-rm);
            update(0,N-1,mp[rm],mp[r],c,0,1);
            update(0,N-1,mp[c],mp[c],r,0,0);
        }
        else{
            cm=query(0,N-1,mp[r],mp[r],0,1);
            ans=max(0,c-cm);
            update(0,N-1,mp[cm],mp[c],r,0,0);
            update(0,N-1,mp[r],mp[r],c,0,1);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
const int N = 400005;
struct ch{
    int x,y;
    char ty;
    ch(int xx,int yy,char tt){
        x=xx;
        y=yy;
        ty=tt;
    }
};
vector<ch> q;
map<int,int> mp;
int st[4*N][2],lazy[4*N][2];
void update(int ss,int se,int l,int r,int val,int i,int ty){
    if(lazy[i][ty]!=-1){
        st[i][ty]=max(st[i][ty],lazy[i][ty]);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],lazy[i][ty]);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],lazy[i][ty]);
        }
        lazy[i][ty]=-1;
    }
    if(ss>se || l>se || r < ss)
        return;
    if(l<=ss &&se<=r){
        st[i][ty]=max(st[i][ty],val);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],val);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],val);
        }
        return;
    }
    int mid=(ss+se)/2;
    update(ss,mid,l,r,val,2*i+1,ty);
    update(mid+1,se,l,r,val,2*i+2,ty);
    st[i][ty]=max(st[2*i+1][ty],st[2*i+2][ty]);
}
int query(int ss,int se,int l,int r,int i,int ty){
    if(lazy[i][ty]!=-1){
        st[i][ty]=max(st[i][ty],lazy[i][ty]);
        if(ss!=se){
            lazy[2*i+1][ty]=max(lazy[2*i+1][ty],lazy[i][ty]);
            lazy[2*i+2][ty]=max(lazy[2*i+2][ty],lazy[i][ty]);
        }
        lazy[i][ty]=-1;
    }
    if(ss>se || ss>r || se<l)
        return -1;
    if(l<=ss && se<=r){
        return st[i][ty];
    }
    int mid=(ss+se)/2;
    return max(query(ss,mid,l,r,2*i+1,ty),query(mid+1,se,l,r,2*i+2,ty));
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,i,m;
    cin>>n>>m;
    for(i=0;i<m;i++){
        int x,y;
        char ty;
        cin>>x>>y>>ty;
        mp[x-1];mp[y-1];
        q.push_back(ch(y-1,x-1,ty));
    }
    int cc=0;
    for(auto it : mp){
        mp[it.first] = cc++;
    }
    memset(st,-1,sizeof(st));
    memset(lazy,-1,sizeof(lazy));
    for(i=0;i<m;i++){
        int r,c,rm,cm,ans;
        r=q[i].x; c=q[i].y;
        if(q[i].ty == 'U'){
            rm=query(0,N-1,mp[c],mp[c],0,0);
            ans=max(0,r-rm);
            update(0,N-1,mp[rm],mp[r],c,0,1);
        }
        else{
            cm=query(0,N-1,mp[r],mp[r],0,1);
            ans=max(0,c-cm);
            update(0,N-1,mp[cm],mp[c],r,0,0);
        }
        cout<<ans<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

const int MAX = 2e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

struct node{
    int val, lazy;
    node *lft, *rt;
    node(){}
    node(int val) : val(val), lft(NULL), rt(NULL){}
};

struct implicit_segtree{
    node *root;
    implicit_segtree(){
        root = new node(0);
    }

    void update(node *now, int L, int R, int i, int j, int val){
        if(i > R || j < L) return;
        if(L >= i && R <= j){
            now->val = max(now->val, val);
            return;
        }

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        if(now->rt == NULL) now->rt = new node(now->val);

        update(now->lft, L, mid, i, j, val);
        update(now->rt, mid+1, R, i, j, val);
    }

    int query(node *now, int L, int R, int idx){
        if(L == R) return now -> val;

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        if(now->rt == NULL) now->rt = new node(now->val);

        if(idx <= mid) return query(now->lft, L, mid, idx);
        else return query(now->rt, mid+1, R, idx);
    }
};

int arr[MAX];
int main(){

    fastio;
    int n,q;
    cin>>n>>q;

    implicit_segtree row;
    implicit_segtree col;

    while(q--){
        int x,y;
        char dir;
        cin>>x>>y>>dir;
        swap(x,y);
        if(dir == 'U'){
            int sesh = col.query(col.root, 1, n, y);
            cout<<(x - sesh)<<"\n";
            if(sesh == x) continue;
            row.update(row.root, 1, n, sesh+1, x, y);
        }
        else{
            int sesh = row.query(row.root, 1, n, x);
            cout<<(y - sesh)<<"\n";
            if(sesh == y) continue;
            col.update(col.root, 1, n, sesh+1, y, x);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

const int MAX = 2e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

struct node{
    int val, lazy;
    node *lft, *rt;
    node(){}
    node(int val) : val(val), lft(NULL), rt(NULL){}
};

struct implicit_segtree{
    node *root;
    implicit_segtree(){
        root = new node(0);
    }

    void update(node *now, int L, int R, int i, int j, int val){
        if(i > R || j < L) return;
        if(L >= i && R <= j){
            now->val = max(now->val, val);
            return;
        }

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        else now->lft->val = max(now->lft->val, now->val);

        if(now->rt == NULL) now->rt = new node(now->val);
        else now->rt->val = max(now->rt->val, now->val);

        update(now->lft, L, mid, i, j, val);
        update(now->rt, mid+1, R, i, j, val);
    }

    int query(node *now, int L, int R, int idx){
        if(L == R) return now -> val;

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        else now->lft->val = max(now->lft->val, now->val);

        if(now->rt == NULL) now->rt = new node(now->val);
        else now->rt->val = max(now->rt->val, now->val);

        if(idx <= mid) return query(now->lft, L, mid, idx);
        else return query(now->rt, mid+1, R, idx);
    }
};

int arr[MAX];
int main(){

    fastio;
    int n,q;
    cin>>n>>q;

    implicit_segtree row;
    implicit_segtree col;

    while(q--){
        int x,y;
        char dir;
        cin>>x>>y>>dir;
        swap(x,y);
        if(dir == 'U'){
            int sesh = col.query(col.root, 1, n, y);
            cout<<(x - sesh)<<"\n";
            if(sesh == x) continue;
            row.update(row.root, 1, n, sesh+1, x, y);
            col.update(col.root, 1, n, y, y, x);
        }
        else{
            int sesh = row.query(row.root, 1, n, x);
            cout<<(y - sesh)<<"\n";
            if(sesh == y) continue;
            col.update(col.root, 1, n, sesh+1, y, x);
            row.update(row.root, 1, n, x, x, y);
        }
    }
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define vii vector<int>
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pdd pair<double,double>
#define pldld pair<long long double, long long double>
#define ff first
#define ss second
#define pb push_back
#define read freopen("alu.txt","r",stdin);
#define write freopen("vorta.txt","w",stdout);
#define fastio ios::sync_with_stdio(false); cin.tie(NULL);
#define PI 2*acos(0.0)
#define DEBUG(x) cerr << #x << " = " << x << endl
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

const int MAX = 2e6 + 5, MOD = 1e9 + 7  , MAXLG = log2(MAX)+1;
const ll inf = 1e18 + 5;

struct node{
    int val, lazy;
    node *lft, *rt;
    node(){}
    node(int val) : val(val), lft(NULL), rt(NULL){}
};

struct implicit_segtree{
    node *root;
    implicit_segtree(){
        root = new node(0);
    }

    void update(node *now, int L, int R, int i, int j, int val){
        if(i > R || j < L) return;
        if(L >= i && R <= j){
            now->val = max(now->val, val);
            return;
        }

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        else now->lft->val = max(now->lft->val, now->val);

        if(now->rt == NULL) now->rt = new node(now->val);
        else now->rt->val = max(now->rt->val, now->val);

        update(now->lft, L, mid, i, j, val);
        update(now->rt, mid+1, R, i, j, val);
    }

    int query(node *now, int L, int R, int idx){
        if(L == R) return now -> val;

        int mid = L + (R - L)/2;
        if(now->lft == NULL) now->lft = new node(now->val);
        else now->lft->val = max(now->lft->val, now->val);

        if(now->rt == NULL) now->rt = new node(now->val);
        else now->rt->val = max(now->rt->val, now->val);

        if(idx <= mid) return query(now->lft, L, mid, idx);
        else return query(now->rt, mid+1, R, idx);
    }
};

int arr[MAX];
int main(){

    fastio;
    int n,q;
    cin>>n>>q;

    implicit_segtree row;
    implicit_segtree col;

    while(q--){
        int x,y;
        char dir;
        cin>>x>>y>>dir;
        swap(x,y);
        if(dir == 'U'){
            int sesh = col.query(col.root, 1, n, y);
            cout<<(x - sesh)<<"\n";
            if(sesh == x) continue;
            row.update(row.root, 1, n, sesh+1, x, y);
        }
        else{
            int sesh = row.query(row.root, 1, n, x);
            cout<<(y - sesh)<<"\n";
            if(sesh == y) continue;
            col.update(col.root, 1, n, sesh+1, y, x);
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e9+5;

struct tree{

    int l,r,v;

    tree *left, *right;

    tree(){
        left = right = NULL;
    }
    tree(int _l,int _r,int _v){
        l = _l,r = _r, v = _v;

        left = right = NULL;
    }

};

void update(tree *cur,int ql,int qr,int upd){

    int l = cur->l, r= cur->r;

    if(qr<l || r<ql)return;
    if(ql<=l && r<=qr){

        cur->v = min(cur->v, upd);

        return;
    }
    int mid = (l+r)/2;
    if(!cur->left)
        cur->left= new tree(l,mid,N);
    if(!cur->right)
        cur->right= new tree(mid+1,r,N);

    update(cur->left,ql,qr,upd);
    update(cur->right,ql,qr,upd);
}

int query(tree *cur,int ind){

    int l = cur->l, r= cur->r;

    if(l==r && l==ind){
        return cur->v;
    }
    int mid = (l+r)/2;

    if(ind<=mid){

        if(!cur->left)
            cur->left= new tree(l,mid,N);

        return min(cur->v, query(cur->left,ind));
    }
    else{
        if(!cur->right)
            cur->right = new tree(mid+1,r,N);

        return min(cur->v, query(cur->right,ind));
    }
}

tree *L,*U;

bool is[N];
int main(){
    int n,q,x,y;
    char c;
    cin>>n>>q;
    L = new tree(1,N,N);
    U = new tree(1,N,N);
    int ind,ql,qr,v;

    while(q--){
        cin>>x>>y>>c;

        if(is[x]){
            printf("0\n");
            continue;
        }
        is[x]= 1;

        if(c=='L'){
            ind = query(L,y);

            if(ind==N){
                printf("%d\n",x);
                ql = 1,qr = x, v = y;
            }

            else{

                ind = n+1-ind;
                printf("%d\n",x-ind);
                qr = x;
                ql = ind+1;
                v= y;
            }
            if(ql<=qr)
                update(U,ql,qr,v);
        }
        else{
            ind = query(U,x);

            if(ind<=y){
                printf("%d\n",y-ind);

                ql = ind+1,qr = y,v = y;
            }
            else{
                printf("%d\n",y);
                ql = 1,qr =y,v = y;
            }

            if(ql<=qr){
                update(L,ql,qr,v);
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e9;

struct tree{
    int l,r,v;

    tree *left, *right;

    tree(){
        left = right = NULL;
    }
    tree(int _l,int _r,int _v){
        l = _l,r = _r, v = _v;

        left = right = NULL;
    }
};

void update(tree *cur,int ql,int qr,int upd){

    int l = cur->l, r= cur->r;

    if(qr<l || r<ql)return;
    if(ql<=l && r<=qr){
        cur->v = min(cur->v, upd);

        return;
    }
    int mid = (l+r)/2;
    if(!cur->left && ql<=mid)
        cur->left= new tree(l,mid,N);
    if(!cur->right && mid+1<=qr)
        cur->right= new tree(mid+1,r,N);

    if(ql<=mid)
    update(cur->left,ql,qr,upd);

    if(mid+1<=qr)
    update(cur->right,ql,qr,upd);
}

int query(tree *cur,int ind){

    int l = cur->l, r= cur->r;

    if(l==r && l==ind){
        return cur->v;
    }
    int mid = (l+r)/2;

    if(ind<=mid){
        if(!cur->left)
            return cur->v;

        return min(cur->v, query(cur->left,ind));
    }
    else{
        if(!cur->right)
            return cur->v;

        return min(cur->v, query(cur->right,ind));
    }
}

tree *L,*U;

map<int,bool> is;
int main(){
    int n,q,x,y;
    char c;
    cin>>n>>q;
    L = new tree(1,N,N);
    U = new tree(1,N,N);
    int ind,ql,qr,v;

    while(q--){
        cin>>x>>y>>c;

        if(is.count(x) ){
            printf("0\n");
            continue;
        }

        is[x]= 1;

        if(c=='L'){
            ind = query(L,y);
            if(ind==N){
                ind = n+1;
            }

            ind = n+1-ind;
            printf("%d\n",x-ind);
            qr = x-1;
            ql = ind+1;
            v= x;

            if(ql<=qr)
                update(U,ql,qr,v);
        }
        else{
            ind = query(U,x);

            if(ind==N)
                ind = n+1;
            ind = n+1 - ind;

            if(ind<=y){
                printf("%d\n",y-ind);

                ql = ind+1,qr = y-1,v = y;
            }
            else{
                assert(0);
            }
            if(ql<=qr){
                update(L,ql,qr,v);
            }
        }
    }
}