#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 && 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);
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N = 4e5+15,M = 2e5+15;

map<int,int> Hash;

int L[N*4],U[N*4];

int maxi;
void update(int *tree,int pos,int l,int r,int ql,int qr,int upd){

    if(r<ql || qr<l)return;

    if(ql<= l && r<=qr){
        tree[pos]= max(tree[pos],upd);
        return;
    }
    int mid = (l+r)/2;

    update(tree,pos*2,l,mid,ql,qr,upd);
    update(tree,pos*2+1,mid+1,r,ql,qr,upd);
}

int query(int *tree,int pos,int l,int r,int ql,int qr){

    if(r<ql || qr<l)
        return 0;

    if(ql<=l && r<=qr)
        return tree[pos];
    int mid = (l+r)/2;

    int ret= tree[pos];
    return max(ret,max(query(tree,pos*2,l,mid,ql,qr) , query(tree,pos*2+1,mid+1,r,ql,qr)));
}

int X[M],Y[M];char c[M];

map<int,int> is;
int main(){
    int n,q,i;
    cin>>n>>q;
    maxi = n+1;
    for(i=1;i<=q;++i){
        cin>>X[i]>>Y[i]>>c[i];
        Hash[X[i]];
        Hash[Y[i]];
    }
    map<int,int>::iterator it;
    int pos=1;
    Hash[0];
    for(it= Hash.begin();it!= Hash.end();++it)
        it->second = pos++;

    int a,b;char t;
    for(i=1;i<=q;++i){
        a = X[i],b = Y[i],t = c[i];

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

        if(t=='L'){

            int x= query(L,1,1,n,Hash[b],Hash[b]);

            printf("%d\n",a-x);

            update(U,1,1,n,Hash[x],Hash[a],b);
        }
        else{

            int y = query(U,1,1,n,Hash[a],Hash[a]);
            printf("%d\n",b-y);
            update(L,1,1,n,Hash[y],Hash[b],a);
        }
    }
}


#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;

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;
            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,v = y;
            }
            else{
                assert(0);
            }
            if(ql<=qr){
                update(L,ql,qr,v);
            }
        }
    }
}


#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)
            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;
            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,v = y;
            }
            else{
                assert(0);
            }
            if(ql<=qr){
                update(L,ql,qr,v);
            }
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

const int N = 4e5+15,M = 2e5+15;

map<int,int> Hash;

int L[N*4],U[N*4];

int maxi;
void update(int *tree,int pos,int l,int r,int ql,int qr,int upd){

    if(r<ql || qr<l)return;

    if(ql<= l && r<=qr){
        tree[pos]= max(tree[pos],upd);
        return;
    }
    int mid = (l+r)/2;

    update(tree,pos*2,l,mid,ql,qr,upd);
    update(tree,pos*2+1,mid+1,r,ql,qr,upd);
}

int query(int *tree,int pos,int l,int r,int ql,int qr){

    if(r<ql || qr<l)
        return 0;

    if(ql<=l && r<=qr)
        return tree[pos];
    int mid = (l+r)/2;

    int ret= tree[pos];
    return max(ret,max(query(tree,pos*2,l,mid,ql,qr) , query(tree,pos*2+1,mid+1,r,ql,qr)));
}

int X[M],Y[M];char c[M];

map<int,int> is;
int main(){
    int n,q,i;
    cin>>n>>q;
    maxi = n+1;
    for(i=1;i<=q;++i){
        cin>>X[i]>>Y[i]>>c[i];
        Hash[X[i]];
        Hash[Y[i]];
    }
    map<int,int>::iterator it;
    int pos=1;
    Hash[0];
    Hash[n];

    for(it= Hash.begin();it!= Hash.end();++it)
        it->second = pos++;

    int a,b;char t;
    for(i=1;i<=q;++i){
        a = X[i],b = Y[i],t = c[i];

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

        if(t=='L'){

            int x= query(L,1,1,pos,Hash[b],Hash[b]);

            printf("%d\n",a-x);

            update(U,1,1,pos,Hash[x],Hash[a],b);
        }
        else{

            int y = query(U,1,1,pos,Hash[a],Hash[a]);
            printf("%d\n",b-y);

            update(L,1,1,pos,Hash[y],Hash[b],a);
        }
    }
}


#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;

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){
                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"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}

template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

const int maxn = 1000000;
struct node{
	int l,r,lazy;
	node* son[2];
};
struct seg_tree{
	node no[maxn*4];
	int cnt;
	node*root;
	node*newnode(int l = 1,int r = 1000000000){
		static int cnt = 1;
		no[cnt].l = l;
		no[cnt].r = r;
		return &no[cnt++];
	}

	seg_tree(){
		root = newnode();
	}
	void update(int l,int r,node*cur,int val){
		if(l>cur->r || r<cur->l)return;
		if(cur->lazy>=val)return;
		if(l<=cur->l && cur->r<=r){
			cur->lazy = val;
		}else{
			int mid = (cur->l+cur->r)/2;
			if(!cur->son[0])cur->son[0] = newnode(cur->l,mid);
			if(!cur->son[1])cur->son[1] = newnode(mid+1,cur->r);
			update(l,r,cur->son[0],val);
			update(l,r,cur->son[1],val);
		}
	}
	void query(int c,node* cur,int&ans){
		if(!cur)return;
		if(c>cur->r || c<cur->l)return;
		ans = max(ans,cur->lazy);
		if(c<=cur->l && cur->r<=c){
			return;
		}else{
			query(c,cur->son[0],ans);
			query(c,cur->son[1],ans);
		}
	}
};

seg_tree horizontal,vertical;
set<int>s;
int getMax(seg_tree&tree,int c){
	int ans = 0;
	tree.query(c,tree.root,ans);
	return ans;
}
int main(){
	int n,q;in(n);in(q);
	REP(i,0,q){
		int x,y;char d[2];
		scanf("%d %d %s",&x,&y,d);
		if(s.count(x)){
			printf("0\n");
			continue;
		}else{
			s.insert(x);
		}
		if(d[0]=='U'){
			int ans = 0;
			vertical.query(x,vertical.root,ans);
			iout(y-ans);
			horizontal.update(ans+1,y,horizontal.root,x);
		}else{
			int ans = 0;
			horizontal.query(y,horizontal.root,ans);
			iout(x-ans);
			vertical.update(ans+1,x,vertical.root,y);
		}
	}
	return 0;
}


#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}

template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

const int maxn = 2500000;
struct node{
	int lazy;
	node* son[2];
};
struct seg_tree{
	node no[maxn*4];
	int cnt;
	node*root;
	node*newnode(){
		static int cnt = 1;
		return &no[cnt++];
	}

	seg_tree(){
		root = newnode();
	}
	void update(int l,int r,node*cur,int val,int L = 1,int R = 1000000000){
		if(l>R || r<L)return;
		if(cur->lazy>=val)return;
		if(l<=L && R<=r){
			cur->lazy = val;
		}else{
			int mid = (L+R)/2;
			if(!cur->son[0])cur->son[0] = newnode();
			if(!cur->son[1])cur->son[1] = newnode();
			update(l,r,cur->son[0],val,L,mid);
			update(l,r,cur->son[1],val,mid+1,R);
		}
	}
	void query(int c,node* cur,int&ans,int L = 1,int R = 1000000000){
		if(!cur)return;
		if(c>R || c<L)return;
		ans = max(ans,cur->lazy);
		if(c<=L && R<=c){
			return;
		}else{
			int mid = (L+R)/2;
			query(c,cur->son[0],ans,L,mid);
			query(c,cur->son[1],ans,mid+1,R);
		}
	}
};

seg_tree horizontal,vertical;
set<int>s;
int getMax(seg_tree&tree,int c){
	int ans = 0;
	tree.query(c,tree.root,ans);
	return ans;
}
int main(){
	int n,q;in(n);in(q);
	REP(i,0,q){
		int x,y;char d[2];
		scanf("%d %d %s",&x,&y,d);
		if(s.count(x)){
			printf("0\n");
			continue;
		}else{
			s.insert(x);
		}
		if(d[0]=='U'){
			int ans = 0;
			vertical.query(x,vertical.root,ans);
			iout(y-ans);
			horizontal.update(ans+1,y,horizontal.root,x);
		}else{
			int ans = 0;
			horizontal.query(y,horizontal.root,ans);
			iout(x-ans);
			vertical.update(ans+1,x,vertical.root,y);
		}
	}
	return 0;
}


#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) (x&(-x))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9+7;
const ld eps = 1e-9;
const int inf = mod;
const db PI = atan(1)*4;
template<typename T>
inline int sign(const T&a){if(a<0)return -1;if(a>0)return 1;return 0;}

template<typename T> inline void in(T &x){
    x = 0; T f = 1; char ch = getchar();
    while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
    while (isdigit(ch))  {x = x * 10 + ch - '0'; ch = getchar();}
    x *= f;
}

const int maxn = 1500000;
struct node{
	int l,r,lazy;
	node* son[2];
};
struct seg_tree{
	node no[maxn*4];
	int cnt;
	node*root;
	node*newnode(int l = 1,int r = 1000000000){
		static int cnt = 1;
		no[cnt].l = l;
		no[cnt].r = r;
		return &no[cnt++];
	}

	seg_tree(){
		root = newnode();
	}
	void update(int l,int r,node*cur,int val){
		if(l>cur->r || r<cur->l)return;
		if(cur->lazy>=val)return;
		if(l<=cur->l && cur->r<=r){
			cur->lazy = val;
		}else{
			int mid = (cur->l+cur->r)/2;
			if(!cur->son[0])cur->son[0] = newnode(cur->l,mid);
			if(!cur->son[1])cur->son[1] = newnode(mid+1,cur->r);
			update(l,r,cur->son[0],val);
			update(l,r,cur->son[1],val);
		}
	}
	void query(int c,node* cur,int&ans){
		if(!cur)return;
		if(c>cur->r || c<cur->l)return;
		ans = max(ans,cur->lazy);
		if(c<=cur->l && cur->r<=c){
			return;
		}else{
			query(c,cur->son[0],ans);
			query(c,cur->son[1],ans);
		}
	}
};

seg_tree horizontal,vertical;
set<int>s;
int getMax(seg_tree&tree,int c){
	int ans = 0;
	tree.query(c,tree.root,ans);
	return ans;
}
int main(){
	int n,q;in(n);in(q);
	REP(i,0,q){
		int x,y;char d[2];
		scanf("%d %d %s",&x,&y,d);
		if(s.count(x)){
			printf("0\n");
			continue;
		}else{
			s.insert(x);
		}
		if(d[0]=='U'){
			int ans = 0;
			vertical.query(x,vertical.root,ans);
			iout(y-ans);
			horizontal.update(ans+1,y,horizontal.root,x);
		}else{
			int ans = 0;
			horizontal.query(y,horizontal.root,ans);
			iout(x-ans);
			vertical.update(ans+1,x,vertical.root,y);
		}
	}
	return 0;
}


// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , q , ans ;
unordered_map <int , bool> mark ;
map <int , pair <int , int>> aXis ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> q ;
	int l , r , type ; char ip ;
	aXis[0] = {-1 , 0} , aXis[n + 1] = {+1 , 0} ;
	for ( int i = 0 ; i < q ; i ++ ) {
		cin >> l >> r >> ip ; type = (ip == 'U' ? +1 : -1) ;
		auto closest = aXis.lower_bound(l) ;
		if ( type == -1 )
			closest -- ;
		ans = abs((*closest).X - l) ;
		if ( type == (*closest).Y.X )
			ans += (*closest).Y.Y ;
		aXis[l] = {type , ans} ;
		cout << (mark[l] == true ? 0 : ans) << "\n" ; mark[l] = true ;
	}
}


// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , q , ans ;
unordered_map <int , bool> mark ;
map <int , pair <int , int>> aXis ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> q ;
	int l , r , type ; char ip ;
	aXis[0] = {-1 , 0} , aXis[n + 1] = {+1 , 0} ;
	for ( int i = 0 ; i < q ; i ++ ) {
		cin >> l >> r >> ip ; type = (ip == 'U' ? +1 : -1) ;
		auto closest = aXis.lower_bound(l) ;
		if ( type == -1 )
			closest -- ;
		ans = abs((*closest).X - l) ;
		if ( type == (*closest).Y.X )
			ans += (*closest).Y.Y ;
		cout << (mark[l] == true ? 0 : ans) << "\n" ;
		if ( mark[l] == false )
			aXis[l] = {type , ans} , mark[l] = true ;
	}
}


// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , q , ans ;
map <int , pair <int , int>> aXis ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> q ;
	int l , r , type ; char ip ;
	aXis[0] = {-1 , 0} , aXis[n + 1] = {+1 , 0} ;
	for ( int i = 0 ; i < q ; i ++ ) {
		cin >> l >> r >> ip ; type = (ip == 'L' ? +1 : -1) ;
		auto closest = aXis.lower_bound(l) ;
		if ( type == +1 )
			closest -- ;
		ans = abs((*closest).X - l) ;
		if ( type == (*closest).Y.X )
			ans += (*closest).Y.Y ;
		aXis[l] = {type , ans} ;
		cout << ans << "\n" ;
	}
}


// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , q , ans ;
unordered_map <int , bool> mark ;
map <int , pair <int , int>> aXis ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> q ;
	int l , r , type ; char ip ;
	aXis[0] = {-1 , 0} , aXis[n + 1] = {+1 , 0} ;
	for ( int i = 0 ; i < q ; i ++ ) {
		cin >> l >> r >> ip ; type = (ip == 'L' ? +1 : -1) ;
		auto closest = aXis.lower_bound(l) ;
		if ( type == +1 )
			closest -- ;
		ans = abs((*closest).X - l) ;
		if ( type == (*closest).Y.X )
			ans += (*closest).Y.Y ;
		aXis[l] = {type , ans} ;
		cout << (mark[l] == true ? 0 : ans) << "\n" ; mark[l] = true ;
	}
}


// BWOTSHEWCHB

#include <bits/stdc++.h>

using namespace std ;

#define pb push_back
#define in insert
#define X first
#define Y second

const int MAXN = 1e6 + 69 , MOD = 1e9 + 7 ;

int n , q , ans ;
unordered_map <int , bool> mark ;
map <int , pair <int , int>> aXis ;

int32_t main() {
	ios::sync_with_stdio(false) ;
	cin.tie(0) ; cout.tie(0) ;
	cin >> n >> q ;
	int l , r , type ; char ip ;
	aXis[0] = {+1 , 0} , aXis[n + 1] = {-1 , 0} ;
	for ( int i = 0 ; i < q ; i ++ ) {
		cin >> l >> r >> ip ; type = (ip == 'L' ? +1 : -1) ;
		auto closest = aXis.lower_bound(l) ;
		if ( type == +1 )
			closest -- ;
		ans = abs((*closest).X - l) ;
		if ( type == (*closest).Y.X )
			ans += (*closest).Y.Y ;
		aXis[l] = {type , ans} ;
		cout << (mark[l] == true ? 0 : ans) << "\n" ; mark[l] = true ;
	}
}


/*
 * if you are interested in the reference code here,
 * see https://github.com/georeth/OJLIBS for more information
 *
 * Solution Author : Georeth Chow <georeth2010@gmail.com>
 */
#include <cstdio>
#include <cmath>
#include <cstring>      // memset
#include <cstdlib>      // malloc
#include <cstdint>      // int64_t
#include <cinttypes>    // PRId64 SCNd64
#include <numeric>      // accumulate, partial_sum, inner_product, iota, adjacent_difference
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <tuple>        // pair, tuple
// #include <iostream>  // no iostream, many drawbacks (mix cstdio with fio, bad performance 2x)
#include <algorithm>
#include <utility>
#include <iterator>
template <typename It>
struct iter_range : std::pair<It, It> {
    typedef std::pair<It, It> base_t;
    using base_t::base_t;
    It begin() { return base_t::first; }
    It end() { return base_t::second; }
};
template <typename It>
iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) {
    using rev_t = std::reverse_iterator<It>;
    return {rev_t(origin.second), rev_t(origin.first)};
}
template <typename Int = int>
struct int_iter {
    Int i;
    explicit int_iter(Int i = 0) : i(i) { }
    Int operator*() const { return i; }
    int_iter &operator++() { ++i; return *this; }
    int_iter &operator--() { --i; return *this; }
    int_iter operator+(Int step) const { return int_iter(i + step); }
    int_iter operator-(Int step) const { return int_iter(i - step); }
    Int operator-(const int_iter &that) const { return i - that.i; }
    int_iter &operator+=(Int step) { i += step; return *this; }
    int_iter &operator-=(Int step) { i -= step; return *this; }
    bool operator==(const int_iter &that) const { return  i == that.i; }
    bool operator!=(const int_iter &that) const { return !(*this == that); }
    Int operator[](Int n) { return i + n; }
    typedef Int difference_type;
    typedef Int value_type;
    typedef Int *pointer;
    typedef Int reference; // not a int container, never reference to int
    typedef std::random_access_iterator_tag iterator_category;
};
template <typename Int>
using int_range = iter_range<int_iter<Int>>;
template <typename Int>
int_range<Int> range(Int b, Int e) { return {int_iter<Int>(b), int_iter<Int>(e > b ? e : b)}; }
template <typename Int>
int_range<Int> range(Int n) { return range(Int(), n); }
template <typename Int>
int_range<Int> nrange(Int n) { return range(Int(1), Int(n+1)); }
template <typename Int>
int_range<Int> inrange(Int b, Int e) { return range(b, Int(e + 1)); }
using namespace std;    // use as solution header. name polution is fine.
#ifdef LOCAL_JUDGE
#  define pr_debug(...) fprintf(stderr, __VA_ARGS__)
#  define pr_line() fprintf(stderr, "%s: %d\n", __FILE__, __LINE__)
#else
#  define pr_debug(...)
#  define pr_line()
#endif
template <typename T>
bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; }
template <typename T>
bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; }
/*
void fio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
*/
/* =====  SOLUTION START  ===== */
set<int> L, U;
int main() {
    // fio();
    int n, q;
    scanf("%d%d", &n, &q);
    L.insert(n + 1);
    U.insert(0);
    for (int _ : range(q)) {
        char buf[10];
        int x;
        scanf("%d%*d%s", &x, buf);
        if (L.count(x) || U.count(x))
            printf("0\n");
        else if (*buf == 'U') {
            int up_l = *L.lower_bound(x);
            printf("%d\n", up_l - x);
            U.insert(x);
        } else {
            int left_u = *--U.lower_bound(x);
            printf("%d\n", x - left_u);
            L.insert(x);
        }
    }
    return 0;
}


/*
 * if you are interested in the reference code here,
 * see https://github.com/georeth/OJLIBS for more information
 *
 * Solution Author : Georeth Chow <georeth2010@gmail.com>
 */
#include <cstdio>
#include <cmath>
#include <cstring>      // memset
#include <cstdlib>      // malloc
#include <cstdint>      // int64_t
#include <cinttypes>    // PRId64 SCNd64
#include <cassert>      // assert
#include <numeric>      // accumulate, partial_sum, inner_product, iota, adjacent_difference
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <tuple>        // pair, tuple
// #include <iostream>  // no iostream, many drawbacks (mix cstdio with fio, bad performance 2x)
#include <algorithm>
#include <utility>
#include <iterator>
template <typename It>
struct iter_range : std::pair<It, It> {
    typedef std::pair<It, It> base_t;
    using base_t::base_t;
    It begin() { return base_t::first; }
    It end() { return base_t::second; }
};
template <typename It>
iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) {
    using rev_t = std::reverse_iterator<It>;
    return {rev_t(origin.second), rev_t(origin.first)};
}
template <typename Int = int>
struct int_iter {
    Int i;
    explicit int_iter(Int i = 0) : i(i) { }
    Int operator*() const { return i; }
    int_iter &operator++() { ++i; return *this; }
    int_iter &operator--() { --i; return *this; }
    int_iter operator+(Int step) const { return int_iter(i + step); }
    int_iter operator-(Int step) const { return int_iter(i - step); }
    Int operator-(const int_iter &that) const { return i - that.i; }
    int_iter &operator+=(Int step) { i += step; return *this; }
    int_iter &operator-=(Int step) { i -= step; return *this; }
    bool operator==(const int_iter &that) const { return  i == that.i; }
    bool operator!=(const int_iter &that) const { return !(*this == that); }
    Int operator[](Int n) { return i + n; }
    typedef Int difference_type;
    typedef Int value_type;
    typedef Int *pointer;
    typedef Int reference; // not a int container, never reference to int
    typedef std::random_access_iterator_tag iterator_category;
};
template <typename Int>
using int_range = iter_range<int_iter<Int>>;
template <typename Int>
int_range<Int> range(Int b, Int e) { return {int_iter<Int>(b), int_iter<Int>(e > b ? e : b)}; }
template <typename Int>
int_range<Int> range(Int n) { return range(Int(), n); }
template <typename Int>
int_range<Int> nrange(Int n) { return range(Int(1), Int(n+1)); }
template <typename Int>
int_range<Int> inrange(Int b, Int e) { return range(b, Int(e + 1)); }
using namespace std;    // use as solution header. name polution is fine.
#ifdef LOCAL_JUDGE
#  define pr_debug(...) fprintf(stderr, __VA_ARGS__)
#  define pr_line() fprintf(stderr, "%s: %d\n", __FILE__, __LINE__)
#else
#  define pr_debug(...)
#  define pr_line()
#endif
template <typename T>
bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; }
template <typename T>
bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; }
/*
void fio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
*/
// http://aggregate.org/MAGIC/
static inline unsigned all_ones(unsigned x) {
    x |= (x >> 1);
    x |= (x >> 2);
    x |= (x >> 4);
    x |= (x >> 8);
    x |= (x >> 16);
    return x;
}
static inline int floor_log2(unsigned x) {
    int ans = 0;
    while (x >>= 1)
	++ans;
    return ans;
}
static inline bool is_pow2(unsigned x) {
    return !(x & (x - 1));
}
static inline unsigned next_pow2(unsigned x) {
    return all_ones(x) + 1;
}
static inline unsigned ceil_pow2(unsigned x) {
    if (is_pow2(x)) return x;
    return next_pow2(x);
}
// floor pow2
static inline int msb32(unsigned int x) {
    x = all_ones(x);
    return x & ~(x >> 1);
}
#include <limits>
template <typename T>
struct binary_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 + t2; }
    T negate(const T &t) { return -t; }
};
template <typename T, T MOD>
struct modular_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return (t1 + t2) % MOD; }
    T negate(const T &t) { return (MOD - t) % MOD; }
};
template <typename T>
struct binary_xor {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 ^ t2; }
    T negate(const T &t) { return t; }
};
template <typename T>
struct binary_max {
    T identity() const { return std::numeric_limits<T>::min(); }
    T operator()(const T &t1, const T &t2) const { return std::max(t1, t2); }
};
template <typename T>
struct binary_min {
    T identity() const { return std::numeric_limits<T>::max(); }
    T operator()(const T &t1, const T &t2) const { return std::min(t1, t2); }
};
#define COMMON_CODE \
    Op op; \
    std::vector<T> vec; \
    int size; /* size of last layer */ \
    int offset; \
    segtree(int n) { \
        size = n; \
        offset = ceil_pow2(n); \
        vec.resize(size + offset + 1, op.identity()); /* ensure every leaf has sibling */ \
    } \
    T &operator[](int i) { \
        return vec[offset + i]; \
    }
template <typename T, typename Op = binary_plus<T>, bool flavour_one = true>
struct segtree;
template <typename T, typename Op>
struct segtree<T, Op, true>
{
    // Flavour I : update element, query range (also query element by operator[])
    //          value(element) = vec[element+offset]
    //          vec[p] = op(vec[2p], vec[2p+1]) always holds
    COMMON_CODE
    void rebuild() {
        for (int i = (offset + size - 1) / 2; i > 0; --i)
            vec[i] = op(vec[i + i], vec[i + i + 1]);
    }
    void increase_element(int p, const T &n) {
        for (p += offset; p; p >>= 1)
            vec[p] = op(n, vec[p]);
    }
    void update_element(int p, const T &n) {
        p += offset;
        vec[p] = n;
        while (p >>= 1)
            vec[p] = op(vec[p + p], vec[p + p + 1]);
    }
    T query_range(int s, int t) {
        return query_include(s, t - 1);
    }
    T query_include(int s, int t) {
        // order is important if op is not commutative
        if (s > t) return op.identity();
        s += offset;
        t += offset;
        T left_acc = vec[s];
        if (s == t) return left_acc;
        T right_acc = vec[t];
        // query exclude ]s, t[ next
        for (; s^t^1; s>>=1, t>>=1) {
            if (~s & 1) left_acc = op(left_acc, vec[s^1]);
            if (t & 1) right_acc = op(vec[t^1], right_acc);
        }
        return op(left_acc, right_acc);
    }
};
template <typename T, typename Op>
struct segtree<T, Op, false>
{
    // Flavour II : query element, increase range (also increase element by operator[])
    //          Op must be commutative
    //          value(element) = sum{j}{vec[(element+offset)/2^j]} (aggregate all values above it)
    COMMON_CODE
    T query_element(int p){
        T ret = op.identity();
        for (p += offset; p; p >>= 1)
            ret = op(vec[p], ret);
        return ret;
    }
    void increase_range(int s, int t, const T &inc) {
        return increase_include(s, t - 1, inc);
    }
    void increase_include(int s, int t, const T &inc) {
        if (s > t) return;
        s += offset;
        t += offset;
        vec[s] = op(inc, vec[s]);
        if (s == t) return;
        vec[t] = op(inc, vec[t]);
        // query exclude ]s, t[ next
        for (; s^t^1; s>>=1, t>>=1) {
            if (~s & 1) vec[s^1] = op(inc, vec[s^1]);
            if (t & 1) vec[t^1] = op(inc, vec[t^1]);
        }
        return;
    }
    // apply internal nodes to leaves, so operator[] gets query_element
    void flatten() {
        for (int i = 1; i < offset; ++i) {
            if (i + i < offset + size) {
                vec[i + i] = op(vec[i], vec[i + i]);
                vec[i + i + 1] = op(vec[i], vec[i + i + 1]); // dummy sibling doesn't matter
            } else break;
            vec[i] = op.identity();
        }
    }
};
#undef COMMON_CODE
/* =====  SOLUTION START  ===== */
vector<pair<int, bool>> input; // x -> isU
int main() {
    // fio();
    int n, q;
    scanf("%d%d", &n, &q);
    set<int> xs;
    for (int _ : range(q)) {
        char buf[10];
        int x;
        scanf("%d%*d%s", &x, buf);
        xs.insert(x);
        input.push_back(make_pair(x, *buf == 'U'));
    }
    map<int, int> critical;
    map<int, int> rev_cri;
    critical.insert(make_pair(0, critical.size()));
    for (auto x : xs) {
        critical.insert(make_pair(x, critical.size()));
    }
    critical.insert(make_pair(n + 1, critical.size()));
    for (auto kv : critical) {
        rev_cri.insert(make_pair(kv.second, kv.first));
    }
    segtree<int, binary_min<int>, false> L(critical[n+1] + 1);
    segtree<int, binary_max<int>, false> U(critical[n+1] + 1);
    L.increase_include(critical[0], critical[n + 1], critical[n + 1]);
    U.increase_include(critical[0], critical[n + 1], critical[0]);
    for (auto kv : input) {
        assert(critical.count(kv.first));
        int x = critical[kv.first];
        bool isU = kv.second;
        if (isU) {
            int l = L.query_element(x);
            printf("%d\n", rev_cri[l] - rev_cri[x]);
            U.increase_include(x, l, x);
            L.increase_include(x, x, x);
        } else {
            int u = U.query_element(x);
            printf("%d\n", rev_cri[x] - rev_cri[u]);
            L.increase_include(u, x, x);
            U.increase_include(x, x, x);
        }
    }
    return 0;
}


/*
 * if you are interested in the reference code here,
 * see https://github.com/georeth/OJLIBS for more information
 *
 * Solution Author : Georeth Chow <georeth2010@gmail.com>
 */
#include <cstdio>
#include <cmath>
#include <cstring>      // memset
#include <cstdlib>      // malloc
#include <cstdint>      // int64_t
#include <cinttypes>    // PRId64 SCNd64
#include <cassert>      // assert
#include <numeric>      // accumulate, partial_sum, inner_product, iota, adjacent_difference
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <tuple>        // pair, tuple
// #include <iostream>  // no iostream, many drawbacks (mix cstdio with fio, bad performance 2x)
#include <algorithm>
#include <utility>
#include <iterator>
template <typename It>
struct iter_range : std::pair<It, It> {
    typedef std::pair<It, It> base_t;
    using base_t::base_t;
    It begin() { return base_t::first; }
    It end() { return base_t::second; }
};
template <typename It>
iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) {
    using rev_t = std::reverse_iterator<It>;
    return {rev_t(origin.second), rev_t(origin.first)};
}
template <typename Int = int>
struct int_iter {
    Int i;
    explicit int_iter(Int i = 0) : i(i) { }
    Int operator*() const { return i; }
    int_iter &operator++() { ++i; return *this; }
    int_iter &operator--() { --i; return *this; }
    int_iter operator+(Int step) const { return int_iter(i + step); }
    int_iter operator-(Int step) const { return int_iter(i - step); }
    Int operator-(const int_iter &that) const { return i - that.i; }
    int_iter &operator+=(Int step) { i += step; return *this; }
    int_iter &operator-=(Int step) { i -= step; return *this; }
    bool operator==(const int_iter &that) const { return  i == that.i; }
    bool operator!=(const int_iter &that) const { return !(*this == that); }
    Int operator[](Int n) { return i + n; }
    typedef Int difference_type;
    typedef Int value_type;
    typedef Int *pointer;
    typedef Int reference; // not a int container, never reference to int
    typedef std::random_access_iterator_tag iterator_category;
};
template <typename Int>
using int_range = iter_range<int_iter<Int>>;
template <typename Int>
int_range<Int> range(Int b, Int e) { return {int_iter<Int>(b), int_iter<Int>(e > b ? e : b)}; }
template <typename Int>
int_range<Int> range(Int n) { return range(Int(), n); }
template <typename Int>
int_range<Int> nrange(Int n) { return range(Int(1), Int(n+1)); }
template <typename Int>
int_range<Int> inrange(Int b, Int e) { return range(b, Int(e + 1)); }
using namespace std;    // use as solution header. name polution is fine.
#ifdef LOCAL_JUDGE
#  define pr_debug(...) fprintf(stderr, __VA_ARGS__)
#  define pr_line() fprintf(stderr, "%s: %d\n", __FILE__, __LINE__)
#else
#  define pr_debug(...)
#  define pr_line()
#endif
template <typename T>
bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; }
template <typename T>
bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; }
/*
void fio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
*/
// http://aggregate.org/MAGIC/
static inline unsigned all_ones(unsigned x) {
    x |= (x >> 1);
    x |= (x >> 2);
    x |= (x >> 4);
    x |= (x >> 8);
    x |= (x >> 16);
    return x;
}
static inline int floor_log2(unsigned x) {
    int ans = 0;
    while (x >>= 1)
	++ans;
    return ans;
}
static inline bool is_pow2(unsigned x) {
    return !(x & (x - 1));
}
static inline unsigned next_pow2(unsigned x) {
    return all_ones(x) + 1;
}
static inline unsigned ceil_pow2(unsigned x) {
    if (is_pow2(x)) return x;
    return next_pow2(x);
}
// floor pow2
static inline int msb32(unsigned int x) {
    x = all_ones(x);
    return x & ~(x >> 1);
}
#include <limits>
template <typename T>
struct binary_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 + t2; }
    T negate(const T &t) { return -t; }
};
template <typename T, T MOD>
struct modular_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return (t1 + t2) % MOD; }
    T negate(const T &t) { return (MOD - t) % MOD; }
};
template <typename T>
struct binary_xor {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 ^ t2; }
    T negate(const T &t) { return t; }
};
template <typename T>
struct binary_max {
    T identity() const { return std::numeric_limits<T>::min(); }
    T operator()(const T &t1, const T &t2) const { return std::max(t1, t2); }
};
template <typename T>
struct binary_min {
    T identity() const { return std::numeric_limits<T>::max(); }
    T operator()(const T &t1, const T &t2) const { return std::min(t1, t2); }
};
#define COMMON_CODE \
    Op op; \
    std::vector<T> vec; \
    int size; /* size of last layer */ \
    int offset; \
    segtree(int n) { \
        size = n; \
        offset = ceil_pow2(n); \
        vec.resize(size + offset + 1, op.identity()); /* ensure every leaf has sibling */ \
    } \
    T &operator[](int i) { \
        return vec[offset + i]; \
    }
template <typename T, typename Op = binary_plus<T>, bool flavour_one = true>
struct segtree;
template <typename T, typename Op>
struct segtree<T, Op, true>
{
    // Flavour I : update element, query range (also query element by operator[])
    //          value(element) = vec[element+offset]
    //          vec[p] = op(vec[2p], vec[2p+1]) always holds
    COMMON_CODE
    void rebuild() {
        for (int i = (offset + size - 1) / 2; i > 0; --i)
            vec[i] = op(vec[i + i], vec[i + i + 1]);
    }
    void increase_element(int p, const T &n) {
        for (p += offset; p; p >>= 1)
            vec[p] = op(n, vec[p]);
    }
    void update_element(int p, const T &n) {
        p += offset;
        vec[p] = n;
        while (p >>= 1)
            vec[p] = op(vec[p + p], vec[p + p + 1]);
    }
    T query_range(int s, int t) {
        return query_include(s, t - 1);
    }
    T query_include(int s, int t) {
        // order is important if op is not commutative
        if (s > t) return op.identity();
        s += offset;
        t += offset;
        T left_acc = vec[s];
        if (s == t) return left_acc;
        T right_acc = vec[t];
        // query exclude ]s, t[ next
        for (; s^t^1; s>>=1, t>>=1) {
            if (~s & 1) left_acc = op(left_acc, vec[s^1]);
            if (t & 1) right_acc = op(vec[t^1], right_acc);
        }
        return op(left_acc, right_acc);
    }
};
template <typename T, typename Op>
struct segtree<T, Op, false>
{
    // Flavour II : query element, increase range (also increase element by operator[])
    //          Op must be commutative
    //          value(element) = sum{j}{vec[(element+offset)/2^j]} (aggregate all values above it)
    COMMON_CODE
    T query_element(int p){
        T ret = op.identity();
        for (p += offset; p; p >>= 1)
            ret = op(vec[p], ret);
        return ret;
    }
    void increase_range(int s, int t, const T &inc) {
        return increase_include(s, t - 1, inc);
    }
    void increase_include(int s, int t, const T &inc) {
        if (s > t) return;
        s += offset;
        t += offset;
        vec[s] = op(inc, vec[s]);
        if (s == t) return;
        vec[t] = op(inc, vec[t]);
        // query exclude ]s, t[ next
        for (; s^t^1; s>>=1, t>>=1) {
            if (~s & 1) vec[s^1] = op(inc, vec[s^1]);
            if (t & 1) vec[t^1] = op(inc, vec[t^1]);
        }
        return;
    }
    // apply internal nodes to leaves, so operator[] gets query_element
    void flatten() {
        for (int i = 1; i < offset; ++i) {
            if (i + i < offset + size) {
                vec[i + i] = op(vec[i], vec[i + i]);
                vec[i + i + 1] = op(vec[i], vec[i + i + 1]); // dummy sibling doesn't matter
            } else break;
            vec[i] = op.identity();
        }
    }
};
#undef COMMON_CODE
/* =====  SOLUTION START  ===== */
vector<pair<int, bool>> input; // x -> isU
int main() {
    // fio();
    int n, q;
    scanf("%d%d", &n, &q);
    set<int> xs;
    for (int _ : range(q)) {
        char buf[10];
        int x;
        scanf("%d%*d%s", &x, buf);
        xs.insert(x);
        input.push_back(make_pair(x, *buf == 'U'));
    }
    map<int, int> critical;
    map<int, int> rev_cri;
    critical.insert(make_pair(0, critical.size()));
    for (auto x : xs) {
        critical.insert(make_pair(x, critical.size()));
    }
    critical.insert(make_pair(n + 1, critical.size()));
    for (auto kv : critical) {
        rev_cri.insert(make_pair(kv.second, kv.first));
    }
    segtree<int, binary_min<int>, false> L(n + 2);
    segtree<int, binary_max<int>, false> U(n + 2);
    L.increase_include(critical[0], critical[n + 1], critical[n + 1]);
    U.increase_include(critical[0], critical[n + 1], critical[0]);
    for (auto kv : input) {
        assert(critical.count(kv.first));
        int x = critical[kv.first];
        bool isU = kv.second;
        if (isU) {
            int l = L.query_element(x);
            printf("%d\n", rev_cri[l] - rev_cri[x]);
            U.increase_include(x, l, x);
            L.increase_include(x, x, x);
        } else {
            int u = U.query_element(x);
            printf("%d\n", rev_cri[x] - rev_cri[u]);
            L.increase_include(u, x, x);
            U.increase_include(x, x, x);
        }
    }
    return 0;
}


/*
 * if you are interested in the reference code here,
 * see https://github.com/georeth/OJLIBS for more information
 *
 * Solution Author : Georeth Chow <georeth2010@gmail.com>
 */
#include <cstdio>
#include <cmath>
#include <cstring>      // memset
#include <cstdlib>      // malloc
#include <cstdint>      // int64_t
#include <cinttypes>    // PRId64 SCNd64
#include <cassert>      // assert
#include <numeric>      // accumulate, partial_sum, inner_product, iota, adjacent_difference
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <tuple>        // pair, tuple
// #include <iostream>  // no iostream, many drawbacks (mix cstdio with fio, bad performance 2x)
#include <algorithm>
#include <utility>
#include <iterator>
template <typename It>
struct iter_range : std::pair<It, It> {
    typedef std::pair<It, It> base_t;
    using base_t::base_t;
    It begin() { return base_t::first; }
    It end() { return base_t::second; }
};
template <typename It>
iter_range<std::reverse_iterator<It>> rev(const iter_range<It> &origin) {
    using rev_t = std::reverse_iterator<It>;
    return {rev_t(origin.second), rev_t(origin.first)};
}
template <typename Int = int>
struct int_iter {
    Int i;
    explicit int_iter(Int i = 0) : i(i) { }
    Int operator*() const { return i; }
    int_iter &operator++() { ++i; return *this; }
    int_iter &operator--() { --i; return *this; }
    int_iter operator+(Int step) const { return int_iter(i + step); }
    int_iter operator-(Int step) const { return int_iter(i - step); }
    Int operator-(const int_iter &that) const { return i - that.i; }
    int_iter &operator+=(Int step) { i += step; return *this; }
    int_iter &operator-=(Int step) { i -= step; return *this; }
    bool operator==(const int_iter &that) const { return  i == that.i; }
    bool operator!=(const int_iter &that) const { return !(*this == that); }
    Int operator[](Int n) { return i + n; }
    typedef Int difference_type;
    typedef Int value_type;
    typedef Int *pointer;
    typedef Int reference; // not a int container, never reference to int
    typedef std::random_access_iterator_tag iterator_category;
};
template <typename Int = int>
using int_range = iter_range<int_iter<Int>>;
template <typename Int>
int_range<Int> range(Int b, Int e) { return {int_iter<Int>(b), int_iter<Int>(e > b ? e : b)}; }
template <typename Int>
int_range<Int> range(Int n) { return range(Int(), n); }
template <typename Int>
int_range<Int> nrange(Int n) { return range(Int(1), Int(n+1)); }
template <typename Int>
int_range<Int> inrange(Int b, Int e) { return range(b, Int(e + 1)); }
using namespace std;    // use as solution header. name polution is fine.
#ifdef LOCAL_JUDGE
#  define pr_debug(...) fprintf(stderr, __VA_ARGS__)
#  define pr_line() fprintf(stderr, "%s: %d\n", __FILE__, __LINE__)
#else
#  define pr_debug(...)
#  define pr_line()
#endif
template <typename T>
bool chmax(T &m, const T &v) { if (v > m) return m = v, true; return false; }
template <typename T>
bool chmin(T &m, const T &v) { if (v < m) return m = v, true; return false; }
/*
void fio() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}
*/
// http://aggregate.org/MAGIC/
static inline unsigned all_ones(unsigned x) {
    x |= (x >> 1);
    x |= (x >> 2);
    x |= (x >> 4);
    x |= (x >> 8);
    x |= (x >> 16);
    return x;
}
static inline int floor_log2(unsigned x) {
    int ans = 0;
    while (x >>= 1)
	++ans;
    return ans;
}
static inline bool is_pow2(unsigned x) {
    return !(x & (x - 1));
}
static inline unsigned next_pow2(unsigned x) {
    return all_ones(x) + 1;
}
static inline unsigned ceil_pow2(unsigned x) {
    if (is_pow2(x)) return x;
    return next_pow2(x);
}
// floor pow2
static inline int msb32(unsigned int x) {
    x = all_ones(x);
    return x & ~(x >> 1);
}
#include <limits>
template <typename T>
struct binary_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 + t2; }
    T negate(const T &t) { return -t; }
};
template <typename T, T MOD>
struct modular_plus {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return (t1 + t2) % MOD; }
    T negate(const T &t) { return (MOD - t) % MOD; }
};
template <typename T>
struct binary_xor {
    T identity() const { return T(); }
    T operator()(const T &t1, const T &t2) const { return t1 ^ t2; }
    T negate(const T &t) { return t; }
};
template <typename T>
struct binary_max {
    T identity() const { return std::numeric_limits<T>::min(); }
    T operator()(const T &t1, const T &t2) const { return std::max(t1, t2); }
};
template <typename T>
struct binary_min {
    T identity() const { return std::numeric_limits<T>::max(); }
    T operator()(const T &t1, const T &t2) const { return std::min(t1, t2); }
};
#define COMMON_CODE \
    Op op; \
    struct node_t { \
        int b, e; \
        T val; \
        node_t *left = nullptr, *right = nullptr; \
        node_t() { } \
        node_t(int b, int e, const T &val) : b(b), e(e), val(val) { } \
    }; \
    std::deque<node_t> pool; \
private: \
    node_t *get_left(node_t *cur, int m) { \
        if (!cur->left) { \
            pool.push_back(node_t(cur->b, m, op.identity())); \
            cur->left = &pool.back(); \
        } \
        return cur->left; \
    } \
    node_t *get_right(node_t *cur, int m) { \
        if (!cur->right) { \
            pool.push_back(node_t(m, cur->e, op.identity())); \
            cur->right = &pool.back(); \
        } \
        return cur->right; \
    } \
public: \
    implicit_segtree(int b, int e) { \
        if (e - b < 1) throw 0; \
        pool.push_back(node_t(b, e, op.identity())); \
    }
template <typename T, typename Op = binary_plus<T>, bool flavour_one = true>
struct implicit_segtree;
template <typename T, typename Op>
struct implicit_segtree<T, Op, true>
{
    // Flavour I : update element, query range (also query element by operator[])
    //          value(element) = vec[element+offset]
    //          vec[p] = op(vec[2p], vec[2p+1]) always holds
    COMMON_CODE
    void increase_element(node_t &p, const T &n) {
        node_t *root = &pool.front();
        if (p < root->b || p >= root->e) throw 0;
        return increase_element_inner(root, p, n);
    }
    void update_element(int p, const T &n) {
        node_t *root = &pool.front();
        if (p < root->b || p >= root->e) throw 0;
        return update_element_inner(root, p, n);
    }
    T query_range(int s, int t) {
        if (s >= t) return op.identity();
        node_t *root = &pool.front();
        if (s < root->b || t > root->e) throw 0;
        return query_range_inner(root, s, t);
    }
    T query_include(int s, int t) {
        return query_range(s, t + 1);
    }
private:
    T query_range_inner(node_t *cur, int s, int t) {
        if (!cur) return op.identity();
        // always overlap
        // inside
        if (s <= cur->b && t >= cur->e)
            return cur->val;
        // partial overlap
        else {
            T ret = op.identity();
            int m = (cur->b + cur->e) / 2;
            if (s < m) ret = op(ret, query_range_inner(cur->left, s, t));
            if (t > m) ret = op(ret, query_range_inner(cur->right, s, t));
            return ret;
        }
    }
    void increase_element_inner(node_t *cur, int p, const T &n) {
        cur->val = op(cur->val, n);
        if (cur->e - cur->b == 1) return;
        int m = (cur->b + cur->e) / 2;
        if (p < m)
            increase_element_inner(get_left(cur, m), p, n);
        else
            increase_element_inner(get_right(cur, m), p, n);
    }
    void update_element_inner(node_t *cur, int p, const T &n) {
        if (cur->e - cur->b == 1) {
            cur->val = n;
            return;
        }
        int m = (cur->b + cur->e) / 2;
        if (p < m)
            update_element_inner(get_left(cur, m), p, n);
        else
            update_element_inner(get_right(cur, m), p, n);
        // child value may change, recalculate aggregated value
        cur->val = op(cur->left ? cur->left->val : op.identity(),
                      cur->right ? cur->right->val : op.identity());
    }
};
template <typename T, typename Op>
struct implicit_segtree<T, Op, false>
{
    // Flavour II : query element, increase range (also increase element by operator[])
    //          Op must be commutative
    //          value(element) = sum{j}{vec[(element+offset)/2^j]} (aggregate all values above it)
    COMMON_CODE
    T query_element(int p) {
        node_t *root = &pool.front();
        if (p < root->b || p >= root->e) throw 0;
        return query_element_inner(root, p);
    }
    void increase_range(int s, int t, const T &inc) {
        if (s >= t) return;
        node_t *root = &pool.front();
        if (s < root->b || t > root->e) throw 0;
        return increase_range_inner(root, s, t, inc);
    }
    void increase_include(int s, int t, const T &inc) {
        increase_range(s, t + 1, inc);
    }
private:
    T query_element_inner(node_t *cur, int p) {
        if (!cur) return op.identity();
        // always overlap
        if (cur->e - cur->b == 1) return cur->val;
        int m = (cur->b + cur->e) / 2;
        if (p < m)
            return op(cur->val, query_element_inner(cur->left, p));
        else
            return op(cur->val, query_element_inner(cur->right, p));
    }
    void increase_range_inner(node_t *cur, int s, int t, const T &inc) {
        // always overlap
        // inside
        if (s <= cur->b && t >= cur->e)
            cur->val = op(inc, cur->val);
        // partial overlap
        else {
            int m = (cur->b + cur->e) / 2;
            if (s < m) increase_range_inner(get_left(cur, m), s, t, inc);
            if (t > m) increase_range_inner(get_right(cur, m), s, t, inc);
        }
    }
};
#undef COMMON_CODE
/* =====  SOLUTION START  ===== */
vector<pair<int, bool>> input; // x -> isU
int main() {
    // fio();
    int n, q;
    scanf("%d%d", &n, &q);
    for (int _ : range(q)) {
        char buf[10];
        int x;
        scanf("%d%*d%s", &x, buf);
        input.push_back(make_pair(x, *buf == 'U'));
    }
    implicit_segtree<int, binary_min<int>, false> L(0, n + 2);
    implicit_segtree<int, binary_max<int>, false> U(0, n + 2);
    L.increase_include(0, n + 1, n + 1);
    U.increase_include(0, n + 1, 0);
    for (auto kv : input) {
        int x = kv.first;
        bool isU = kv.second;
        if (isU) {
            int l = L.query_element(x);
            printf("%d\n", l - x);
            U.increase_include(x, l, x);
            L.increase_include(x, x, x);
        } else {
            int u = U.query_element(x);
            printf("%d\n", x - u);
            L.increase_include(u, x, x);
            U.increase_include(x, x, x);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;

int n, q;
struct intre
{
    ll x, y;
    char tip;
};
intre v[200002];

int pc[2][200002];
int aib[2][200002];
void update(int nod, int poz)
{
    for(; poz <= pc[nod][0]; poz += (poz & (-poz)))
        aib[nod][poz]++;
}
int compute(int nod, int poz)
{
    int ans = 0;
    for(; poz; poz -= (poz & (-poz)))
        ans += aib[nod][poz];
    return ans;
}
map<int, int> poz[2];
map<int, int> scos;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    for(int i = 1; i <= q; ++i)
    {
        cin >> v[i].x >> v[i].y >> v[i].tip;
        swap(v[i].x, v[i].y);
        if(v[i].tip == 'U')
            pc[0][++pc[0][0]] = v[i].x;
        else
            pc[1][++pc[1][0]] = v[i].y;
    }
    sort(pc[0]+1, pc[0]+pc[0][0]+1);
    sort(pc[1]+1, pc[1]+pc[1][0]+1);
    for(int i = 0; i <= 1; ++i)
    {
        for(int j = 1; j <= pc[i][0]; ++j)
            poz[i][pc[i][j]] = j;
    }
    for(int i = 1; i <= q; ++i)
    {
        if(scos.find(v[i].x) != scos.end())
        {
            cout << 0 << '\n';
            continue;
        }
        if(v[i].tip == 'U')
        {
            int st = 1;
            int dr = pc[1][0];
            int ans = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[1][mid] >= v[i].y)
                    ans = mid, dr = mid - 1;
                else
                    st = mid + 1;
            }
            if(ans == 0)
                cout << v[i].x << '\n';
            else
            {
                int val = compute(1, ans - 1);
                if(compute(1, pc[1][0]) == val)
                    cout << v[i].x << '\n';
                else
                {
                    int LL = ans;
                    int RR = pc[1][0];
                    int stop = 0;
                    while(LL <= RR)
                    {
                        int mid = (LL + RR) / 2;
                        if(compute(1, mid) > val)
                            stop = mid, RR = mid - 1;
                        else
                            LL = mid + 1;
                    }
                    cout << v[i].x - ((n + 1) - pc[1][stop]) << '\n';
                }
            }
            update(0, poz[0][v[i].x]);
        }
        else
        {
            int st = 1;
            int dr = pc[0][0];
            int ans = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[0][mid] >= v[i].x)
                    ans = mid, dr = mid - 1;
                else
                    st = mid + 1;
            }
            if(ans == 0)
                cout << v[i].y << '\n';
            else
            {
                int val = compute(0, ans - 1);
                if(compute(0, pc[0][0]) == val)
                    cout << v[i].y << '\n';
                else
                {
                    int LL = ans;
                    int RR = pc[0][0];
                    int stop = 0;
                    while(LL <= RR)
                    {
                        int mid = (LL + RR) / 2;
                        if(compute(0, mid) > val)
                            stop = mid, RR = mid - 1;
                        else
                            LL = mid + 1;
                    }
                    cout << v[i].y - ((n + 1) - pc[0][stop]) << '\n';
                }
            }
            update(1, poz[1][v[i].y]);
        }
        scos[v[i].x] = 1;
    }
    return 0;
}


#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007

using namespace std;

typedef long long ll;

int n, q;
struct intre
{
    int x, y;
    char tip;
};
intre v[200002];

int pc[2][200002];
map<int, int> poz[2];
map<int, int> scos;

int aint[2][800002];
int lazy[2][800002];
void propagate(int tip, int nod, int st, int dr)
{
    aint[tip][nod] = max(aint[tip][nod], lazy[tip][nod]);
    if(st != dr)
    {
        lazy[tip][nod << 1] = max(lazy[tip][nod << 1], lazy[tip][nod]);
        lazy[tip][nod << 1|1] = max(lazy[tip][nod << 1|1], lazy[tip][nod]);
    }
    lazy[tip][nod] = 0;
}
void update(int tip, int nod, int st, int dr, int L, int R, int val)
{
    if(lazy[tip][nod])
        propagate(tip, nod, st, dr);
    if(L <= st && dr <= R)
    {
        lazy[tip][nod] = val;
        return;
    }
    if(dr < L || st > R)
        return;
    int mid = (st + dr) / 2;
    update(tip, nod << 1, st, mid, L, R, val);
    update(tip, nod << 1|1, mid+1, dr, L, R, val);
    aint[tip][nod] = max(aint[tip][nod << 1], aint[tip][nod << 1|1]);
}
int query(int tip, int nod, int st, int dr, int val)
{
    if(lazy[tip][nod])
        propagate(tip, nod, st, dr);
    if(st == dr)
        return aint[tip][nod];
    int mid = (st + dr) / 2;
    int ans;
    if(val <= mid)
        ans = query(tip, nod << 1, st, mid, val);
    else
        ans = query(tip, nod << 1|1, mid+1, dr, val);
    aint[tip][nod] = max(aint[tip][nod << 1], aint[tip][nod << 1|1]);
    return ans;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> q;
    for(int i = 1; i <= q; ++i)
    {
        cin >> v[i].x >> v[i].y >> v[i].tip;
        swap(v[i].x, v[i].y);
        if(v[i].tip == 'U')
            pc[0][++pc[0][0]] = v[i].y;
        else
            pc[1][++pc[1][0]] = v[i].x;
    }
    sort(pc[0]+1, pc[0]+pc[0][0]+1);
    sort(pc[1]+1, pc[1]+pc[1][0]+1);
    for(int i = 0; i <= 1; ++i)
    {
        for(int j = 1; j <= pc[i][0]; ++j)
            poz[i][pc[i][j]] = j;
    }
    for(int i = 1; i <= q; ++i)
    {
        if(scos.find(v[i].x) != scos.end())
        {
            cout << 0 << '\n';
            continue;
        }
        if(v[i].tip == 'U')
        {
            int ans = query(0, 1, 1, pc[0][0], poz[0][v[i].y]);
           // cout << poz[0][v[i].x] << " " << ans << '\n';
            cout << v[i].x - ans << '\n';
            int min_line = max(1, v[i].x - (v[i].x - ans));
            int max_line = v[i].x;
            int st = 1;
            int dr = pc[1][0];
            ans = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[1][mid] >= min_line)
                    ans = mid, dr = mid - 1;
                else
                    st = mid + 1;
            }
            st = 1;
            dr = pc[1][0];
            int ans2 = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[1][mid] <= max_line)
                    ans2 = mid, st = mid + 1;
                else
                    dr = mid - 1;
            }
            if(ans <= ans2)
                update(1, 1, 1, pc[1][0], ans, ans2, v[i].y);
        }
        else
        {
            int ans = query(1, 1, 1, pc[1][0], poz[1][v[i].x]);
           // cout << poz[1][v[i].x] << " " << ans << '\n';
            cout << v[i].y - ans << '\n';
            int min_column = max(1, v[i].y - (v[i].y - ans));
            int max_column = v[i].y;
            int st = 1;
            int dr = pc[0][0];
            ans = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[0][mid] >= min_column)
                    ans = mid, dr = mid - 1;
                else
                    st = mid + 1;
            }
            st = 1;
            dr = pc[0][0];
            int ans2 = 0;
            while(st <= dr)
            {
                int mid = (st + dr) / 2;
                if(pc[0][mid] <= max_column)
                    ans2 = mid, st = mid + 1;
                else
                    dr = mid - 1;
            }
            if(ans <= ans2)
                update(0, 1, 1, pc[0][0], ans, ans2, v[i].x);
        }
        scos[v[i].x] = 1;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+100;
typedef long long ll;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

struct segment_tree{
   int tag[N*4];
   #define lc x<<1
   #define rc x<<1|1
   #define mid (l+r)/2
   inline void modify(int x,int l,int r,int ql,int qr,int v){
      if(ql > r || qr < l)return ;
      if(ql <= l && r <= qr){
         tag[x] = max(tag[x],v);
         return ;
      }
      modify(lc,l,mid,ql,qr,v); modify(rc,mid+1,r,ql,qr,v);
   }
   inline int query(int x,int l,int r,int pos){
      if(l == r)return tag[x];
      if(pos <= mid)return max(tag[x],query(lc,l,mid,pos));
      else return max(tag[x],query(rc,mid+1,r,pos));
   }
}s[2];

int x[N],y[N],xb[N],yb[N];
char tpe[N];
int cntx,cnty;
int n,q;

int main(){
   scanf("%d%d",&n,&q);
   fr(i,1,q){
      scanf("%d%d %c",x+i,y+i,tpe+i);
      xb[i] = x[i]; yb[i] = y[i];
   }
   sort(xb+1,xb+q+1); sort(yb+1,yb+q+1);
   cntx = unique(xb+1,xb+q+1)-xb-1; cnty = unique(yb+1,yb+q+1)-yb-1;

   ll ans = 0;
   fr(i,1,q){
      x[i] = lower_bound(xb+1,xb+cntx+1,x[i])-xb;
      y[i] = lower_bound(yb+1,yb+cnty+1,y[i])-yb;
      if(tpe[i] == 'U'){
         int mxv = s[1].query(1,1,cnty,y[i]);
         ans += xb[x[i]]-xb[mxv];
         s[0].modify(1,1,cntx,mxv+1,x[i],y[i]);
      } else {
         int mxv = s[0].query(1,1,cntx,x[i]);
         ans += yb[y[i]]-yb[mxv];
         s[1].modify(1,1,cnty,mxv+1,y[i],x[i]);
      }
      printf("%lld\n",ans);
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N = 2e5+100;
typedef long long ll;
#define fr(i,a,b) for(int i = a;i <= b; ++i)
#define nfr(i,a,b) for(int i = a;i >= b; --i)

struct segment_tree{
   int tag[N*4];
   #define lc x<<1
   #define rc x<<1|1
   #define mid (l+r)/2
   inline void modify(int x,int l,int r,int ql,int qr,int v){
      if(ql > r || qr < l)return ;
      if(ql <= l && r <= qr){
         tag[x] = max(tag[x],v);
         return ;
      }
      modify(lc,l,mid,ql,qr,v); modify(rc,mid+1,r,ql,qr,v);
   }
   inline int query(int x,int l,int r,int pos){
      if(l == r)return tag[x];
      if(pos <= mid)return max(tag[x],query(lc,l,mid,pos));
      else return max(tag[x],query(rc,mid+1,r,pos));
   }
}s[2];

int x[N],y[N],xb[N],yb[N];
int visx[N],visy[N];
char tpe[N];
int cntx,cnty;
int n,q;

int main(){
   scanf("%d%d",&n,&q);
   fr(i,1,q){
      scanf("%d%d %c",x+i,y+i,tpe+i);
      xb[i] = x[i]; yb[i] = y[i];
   }
   sort(xb+1,xb+q+1); sort(yb+1,yb+q+1);
   cntx = unique(xb+1,xb+q+1)-xb-1; cnty = unique(yb+1,yb+q+1)-yb-1;

   ll ans = 0;
   fr(i,1,q){
      x[i] = lower_bound(xb+1,xb+cntx+1,x[i])-xb;
      y[i] = lower_bound(yb+1,yb+cnty+1,y[i])-yb;
      if(tpe[i] == 'U'){
         if(visx[x[i]] == 1){
            puts("0"); continue;
         }
         visx[x[i]] = 1;
         int mxv = s[0].query(1,1,cntx,x[i]);
         ans = yb[y[i]]-yb[mxv];
         s[1].modify(1,1,cnty,mxv+1,y[i],x[i]);
      } else {
         if(visy[y[i]] == 1){
            puts("0"); continue ;
         }
         visy[y[i]] = 1;
         int mxv = s[1].query(1,1,cnty,y[i]);
         ans = xb[x[i]]-xb[mxv];
         s[0].modify(1,1,cntx,mxv+1,x[i],y[i]);
      }
      printf("%lld\n",ans);
   }
   return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=4000005;
struct seg
{
	int tr[N],lc[N],rc[N],c=1,rt=1;
	void update(int &k,int l,int r,int a,int b,int v)
	{
		if(a>b)
			return;
		if(!k) k=++c;
		if(l==a&&r==b)
		{
			tr[k]=max(tr[k],v);
			return;
		}
		int mid=l+r>>1;
		if(b<=mid) update(lc[k],l,mid,a,b,v);
		else if(a>mid) update(rc[k],mid+1,r,a,b,v);
		else update(lc[k],l,mid,a,mid,v),update(rc[k],mid+1,r,mid+1,b,v);
	}
	int query(int k,int l,int r,int x)
	{
		if(!k) return 0;
		if(l==r)
			return tr[k];
		int mid=l+r>>1;
		if(x<=mid) return max(tr[k],query(lc[k],l,mid,x));
		else return max(tr[k],query(rc[k],mid+1,r,x));
	}
}t1,t2;
int n,q;
set<int>s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	while(q--)
	{
		int x,y;
		char t;
		cin>>x>>y>>t;
		if(s.count(x))
		{
			cout<<0<<endl;
			continue;
		}
		s.insert(x);
		if(t=='U')
		{
			int p=t1.query(1,1,n,x)+1;
			cout<<y-p+1<<endl;
			t2.update(t2.rt,1,n,p,y,x);
		}
		else
		{
			int p=t2.query(1,1,n,y)+1;
			cout<<x-p+1<<endl;
			t1.update(t1.rt,1,n,p,x,y);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
struct seg
{
	int tr[N],lc[N],rc[N],c=1,rt=1;
	void update(int &k,int l,int r,int a,int b,int v)
	{
		if(a>b)
			return;
		if(!k) k=++c;
		if(l==a&&r==b)
		{
			tr[k]=max(tr[k],v);
			return;
		}
		int mid=l+r>>1;
		if(b<=mid) update(lc[k],l,mid,a,b,v);
		else if(a>mid) update(rc[k],mid+1,r,a,b,v);
		else update(lc[k],l,mid,a,mid,v),update(rc[k],mid+1,r,mid+1,b,v);
	}
	int query(int k,int l,int r,int x)
	{
		if(!k) return 0;
		if(l==r)
			return tr[k];
		int mid=l+r>>1;
		if(x<=mid) return max(tr[k],query(lc[k],l,mid,x));
		else return max(tr[k],query(rc[k],mid+1,r,x));
	}
}t1,t2;
int n,q;
set<int>s;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	while(q--)
	{
		int x,y;
		char t;
		cin>>x>>y>>t;
		if(s.count(x))
		{
			cout<<0<<endl;
			continue;
		}
		s.insert(x);
		if(t=='U')
		{
			int p=t1.query(1,1,n,x)+1;
			cout<<y-p+1<<endl;
			t2.update(t2.rt,1,n,p,y,x);
		}
		else
		{
			int p=t2.query(1,1,n,y)+1;
			cout<<x-p+1<<endl;
			t1.update(t1.rt,1,n,p,x,y);
		}
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
struct seg
{
	int tr[N],lc[N],rc[N],c=1,rt=1;
	void update(int &k,int l,int r,int a,int b,int v)
	{
		if(a>b)
			return;
		if(!k) k=++c;
		if(l==a&&r==b)
		{
			tr[k]=max(tr[k],v);
			return;
		}
		int mid=l+r>>1;
		if(b<=mid) update(lc[k],l,mid,a,b,v);
		else if(a>mid) update(rc[k],mid+1,r,a,b,v);
		else update(lc[k],l,mid,a,mid,v),update(rc[k],mid+1,r,mid+1,b,v);
	}
	int query(int k,int l,int r,int x)
	{
		if(!k) return 0;
		if(l==r)
			return tr[k];
		int mid=l+r>>1;
		if(x<=mid) return max(tr[k],query(lc[k],l,mid,x));
		else return max(tr[k],query(rc[k],mid+1,r,x));
	}
}t1,t2;
int n,q;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>q;
	while(q--)
	{
		int x,y;
		char t;
		cin>>x>>y>>t;
		if(t=='U')
		{
			int p=t1.query(1,1,n,x)+1;
			cout<<y-p+1<<endl;
			t2.update(t2.rt,1,n,p,y,x);
		}
		else
		{
			int p=t2.query(1,1,n,y)+1;
			cout<<x-p+1<<endl;
			t1.update(t1.rt,1,n,p,x,y);
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
//>>>>>>>>>>>>>>>>>>>>>>>>>>>

const int N = 6e6 + 7;

map  < pair <int, pair <int, int> >, int> mrk;

int mxn = 1e9 + 7;

struct node {
	int seg = 0;
	node *lc = 0, *rc = 0;
	void add(int l, int r, int val, int s = 0, int e = mxn) {
		if (r <= s || e <= l)
			return;
		if (l <= s && e <= r) {
			seg = max(seg, val);
			return;
		}
		if (!lc)
			lc = new node;
		if (!rc)
			rc = new node;
		lc->add(l, r, val, s, mid);
		rc->add(l, r, val, mid, e);
	}
	int get(int p, int s = 0, int e = mxn) {
		if (e - s == 1)
			return seg;
		if (!lc)
			lc = new node;
		if (!rc)
			rc = new node;
		if (p < mid)
			return max(seg, lc->get(p, s, mid));
		else
			return max(seg, rc->get(p, mid, e));
	}
};
node *rt[2];
int main() {
	rt[0] = new node;
	rt[1] = new node;
	int n, q;
	scanf("%d%d", &n, &q);
	while (q--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		bool b = 1;
		if (c == 'U')
			b = 0;
		if (mrk[{b, {x, y}}]) {
			printf("%d ", 0);
			continue;
		}
		mrk[{b, {x, y}}] = 1;
		int t;
		if (b == 0) {
			t = rt[0]->get(x);
			printf("%d ", y - t);
			rt[1]->add(t + 1, y + 1, x);
		}
		else {
			t = rt[1]->get(y);
			printf("%d ", x - t);
			rt[0]->add(t + 1, x + 1, y);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
//>>>>>>>>>>>>>>>>>>>>>>>>>>>

const int N = 6e6 + 7;

map <int, int> seg[2];

int mxn = 1e9 + 7;
int get(int p, int tp, int v = 1, int s = 0, int e = mxn) {
	if (e - s == 1)
		return seg[tp][v];
	if (p < mid)
		return max(seg[tp][v], get(p, tp, v * 2, s, mid));
	else
		return max(seg[tp][v], get(p, tp, v * 2 + 1, mid, e));
}
void add(int tp, int l, int r, int val, int v = 1, int s = 0, int e = mxn) {
	if (r <= s || e <= l)
		return;
	if (l <= s && e <= r) {
		seg[tp][v] = max(seg[tp][v], val);
	   	return;
	}
	add(tp, l, r, val, v * 2, s, mid);
	add(tp, l, r, val, v * 2 + 1, mid, e);
}

int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	while (q--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		bool b = 1;
		if (c == 'U')
			b = 0;
		int t;
		if (b == 0) {
			t = get(x, 0);
			printf("%d ", y - t);
			add(1, 1, y + 1, x);
		}
		else {
			t = get(y, 1);
			printf("%d ", x - t);
			add(0, 1, x + 1, y);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
//>>>>>>>>>>>>>>>>>>>>>>>>>>>

const int N = 6e6 + 7;

map <int, int> seg[2];
map  < pair <int, pair <int, int> >, int> mrk;
int mxn = 1e9 + 7;
int get(int p, int tp, int v = 1, int s = 0, int e = mxn) {
	if (e - s == 1)
		return seg[tp][v];
	if (p < mid)
		return max(seg[tp][v], get(p, tp, v * 2, s, mid));
	else
		return max(seg[tp][v], get(p, tp, v * 2 + 1, mid, e));
}
void add(int tp, int l, int r, int val, int v = 1, int s = 0, int e = mxn) {
	if (r <= s || e <= l)
		return;
	if (l <= s && e <= r) {
		seg[tp][v] = max(seg[tp][v], val);
	   	return;
	}
	add(tp, l, r, val, v * 2, s, mid);
	add(tp, l, r, val, v * 2 + 1, mid, e);
}

int main() {
	int n, q;
	scanf("%d%d", &n, &q);
	while (q--) {
		int x, y;
		char c;
		scanf("%d%d %c", &x, &y, &c);
		bool b = 1;
		if (c == 'U')
			b = 0;
		if (mrk[{b, {x, y}}]) {
			printf("%d ", 0);
			continue;
		}
		mrk[{b, {x, y}}] = 1;
		int t;
		if (b == 0) {
			t = get(x, 0);
			printf("%d ", y - t);
			add(1, t + 1, y + 1, x);
		}
		else {
			t = get(y, 1);
			printf("%d ", x - t);
			add(0, t + 1, x + 1, y);
		}
	}

	return 0;
}


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

const int MAX_M = 200 * 1000 + 10;
int qx[MAX_M], qy[MAX_M], tmpx[MAX_M], tmpy[MAX_M];
char qc[MAX_M];
int n, m;

struct segment_tree {
	int seg[4 * MAX_M];

	segment_tree() {
		memset(seg, -1, sizeof seg);
	}

	void modify(int x, int y, int k, int id = 1, int l = 0, int r = m) {
		if (x >= r || y <= l)
			return;
		if (x <= l && y >= r) {
			seg[id] = max(seg[id], k);
			return;
		}
		int mid = (l + r) / 2;
		modify(x, y, k, id * 2, l, mid);
		modify(x, y, k, id*2+1, mid, r);
	}

	int get(int x, int id = 1, int l = 0, int r = m) {
		if (l == r - 1)
			return seg[id];
		int mid = (l + r) / 2;
		if (x < mid)
			return max(seg[id], get(x, id * 2, l, mid));
		else
			return max(seg[id], get(x, id*2+1, mid, r));
	}
} st[2];

void read_input() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> qx[i] >> qy[i] >> qc[i];
		tmpx[i] = qx[i];
		tmpy[i] = qy[i];
	}
	sort(tmpx, tmpx + m);
	sort(tmpy, tmpy + m);
	for (int i = 0; i < m; i++) {
		qx[i] = lower_bound(tmpx, tmpx + m, qx[i]) - tmpx;
		qy[i] = lower_bound(tmpy, tmpy + m, qy[i]) - tmpy;
	}
}

void print_output() {
	map<pair<int, int>, bool> mark;
	for (int i = 0; i < m; i++) {
		if (mark[{qx[i], qy[i]}]) {
			cout << 0 << endl;
			continue;
		}
		mark[{qx[i], qy[i]}] = true;
		int x[] = {qx[i], qy[i]};
		bool d = (qc[i] == 'L');
		int w = st[d].get(x[d]);
		st[!d].modify(w + 1, x[!d], x[d]);
		if (d)
			cout << tmpx[qx[i]] - (w == -1? 0: tmpx[w]) << endl;
		else
			cout << tmpy[qy[i]] - (w == -1? 0: tmpy[w]) << endl;
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	print_output();
}


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

const int MAX_M = 200 * 1000 + 10;
int qx[MAX_M], qy[MAX_M], tmpx[MAX_M], tmpy[MAX_M];
char qc[MAX_M];
int n, m;

struct segment_tree {
	int seg[4 * MAX_M];

	segment_tree() {
		memset(seg, -1, sizeof seg);
	}

	void modify(int x, int y, int k, int id = 1, int l = 0, int r = m) {
		if (x >= r || y <= l)
			return;
		if (x <= l && y >= r) {
			seg[id] = max(seg[id], k);
			return;
		}
		int mid = (l + r) / 2;
		modify(x, y, k, id * 2, l, mid);
		modify(x, y, k, id*2+1, mid, r);
	}

	int get(int x, int id = 1, int l = 0, int r = m) {
		if (l == r - 1)
			return seg[id];
		int mid = (l + r) / 2;
		if (x < mid)
			return max(seg[id], get(x, id * 2, l, mid));
		else
			return max(seg[id], get(x, id*2+1, mid, r));
	}
} st[2];

void read_input() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> qx[i] >> qy[i] >> qc[i];
		tmpx[i] = qx[i];
		tmpy[i] = qy[i];
	}
	sort(tmpx, tmpx + m);
	sort(tmpy, tmpy + m);
	for (int i = 0; i < m; i++) {
		qx[i] = lower_bound(tmpx, tmpx + m, qx[i]) - tmpx;
		qy[i] = lower_bound(tmpy, tmpy + m, qy[i]) - tmpy;
	}
}

void print_output() {
	for (int i = 0; i < m; i++) {
		int x[] = {qx[i], qy[i]};
		bool d = (qc[i] == 'L');
		int w = st[d].get(x[d]);
		st[!d].modify(w + 1, x[!d] + 1, x[d]);
		if (d)
			cout << tmpx[qx[i]] - (w == -1? 0: tmpx[w]) << endl;
		else
			cout << tmpy[qy[i]] - (w == -1? 0: tmpy[w]) << endl;
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	print_output();
}


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

const int MAX_M = 200 * 1000 + 10;
int qx[MAX_M], qy[MAX_M], tmpx[MAX_M], tmpy[MAX_M];
char qc[MAX_M];
int n, m;

struct segment_tree {
	int seg[4 * MAX_M];

	segment_tree() {
		memset(seg, -1, sizeof seg);
	}

	void modify(int x, int y, int k, int id = 1, int l = 0, int r = m) {
		if (x >= r || y <= l)
			return;
		if (x <= l && y >= r) {
			seg[id] = max(seg[id], k);
			return;
		}
		int mid = (l + r) / 2;
		modify(x, y, k, id * 2, l, mid);
		modify(x, y, k, id*2+1, mid, r);
	}

	int get(int x, int id = 1, int l = 0, int r = m) {
		if (l == r - 1)
			return seg[id];
		int mid = (l + r) / 2;
		if (x < mid)
			return max(seg[id], get(x, id * 2, l, mid));
		else
			return max(seg[id], get(x, id*2+1, mid, r));
	}
} st[2];

void read_input() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> qx[i] >> qy[i] >> qc[i];
		tmpx[i] = qx[i];
		tmpy[i] = qy[i];
	}
	sort(tmpx, tmpx + m);
	sort(tmpy, tmpy + m);
	for (int i = 0; i < m; i++) {
		qx[i] = lower_bound(tmpx, tmpx + m, qx[i]) - tmpx;
		qy[i] = lower_bound(tmpy, tmpy + m, qy[i]) - tmpy;
	}
}

void print_output() {
	map<pair<int, int>, bool> mark;
	for (int i = 0; i < m; i++) {
		int x[] = {qx[i], qy[i]};
		bool d = (qc[i] == 'L');
		int w = st[d].get(x[d]);
		st[!d].modify(w + 1, x[!d], x[d]);
		if (mark[{qx[i], qy[i]}])
			cout << 0 << endl;
		else if (d)
			cout << tmpx[qx[i]] - (w == -1? 0: tmpx[w]) << endl;
		else
			cout << tmpy[qy[i]] - (w == -1? 0: tmpy[w]) << endl;
		mark[{qx[i], qy[i]}] = true;
	}
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	read_input();
	print_output();
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<18];
  int lazy[1<<18];
  void push(int w) {
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<19];
  int lazy[1<<19];
  void push(int w, int L, int R) {
    st[w] = max(st[w], lazy[w]);
    if (L==R) return;
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w, L, R);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w, L, R);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w, L, R);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
      visited.insert(x);
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int n, q;
set<int> u;
set<int> l;
set<int> used;
int x, y;
char dir;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    scanf("%d%d", &x, &y);
    scanf(" %c", &dir);
    if (used.count(x) != 0) printf("0\n");
    else {
      if (dir == 'U') {
        set<int>::iterator it = l.upper_bound(x);
        if (it == l.end()) printf("%d\n", n-x+1);
        else printf("%d\n", *it-x);
        u.insert(y);
      } else {
        set<int>::iterator it = u.upper_bound(y);
        if (it == u.end()) printf("%d\n", n-y+1);
        else printf("%d\n", *it-y);
        l.insert(x);
      }
      used.insert(x);
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<20];
  int lazy[1<<20];
  void push(int w) {
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
      visited.insert(x);
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<18];
  int lazy[1<<18];
  void push(int w) {
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<18];
  int lazy[1<<18];
  void push(int w) {
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
      visited.insert(x);
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<19];
  int lazy[1<<19];
  void push(int w, int L, int R) {
    if (L==R) return;
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w, L, R);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w, L, R);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w, L, R);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
      visited.insert(x);
    }
  }
}


#include <iostream>
#include <cstdio>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
#define MP make_pair

class ST {
private:
  int size;
  int st[1<<19];
  int lazy[1<<19];
  void push(int w) {
    st[w] = max(st[w], lazy[w]);
    lazy[2*w] = max(lazy[2*w], lazy[w]);
    lazy[2*w+1] = max(lazy[2*w+1], lazy[w]);
  }
  void updateI(int w, int L, int R, int a, int b, int c) {
    push(w);
    if (L>b||a>R) return;
    if (L>=a&&b>=R) {
      lazy[w] = max(c, lazy[w]);
      push(w);
    } else {
      updateI(2*w, L, (L+R)/2, a, b, c), updateI(2*w+1, (L+R)/2+1, R, a, b, c);
      st[w] = min(st[2*w], st[2*w+1]);
    }
  }
  int queryI(int w, int L, int R, int a) {
    push(w);
    if (L>a||a>R) return size+1;
    if (L>=a&&a>=R) return st[w];
    return min(queryI(2*w, L, (L+R)/2, a), queryI(2*w+1, (L+R)/2+1, R, a));
  }
public:
  ST(int sz=0) {
    size = sz;
    memset(st, 0, sizeof st);
    memset(lazy, 0, sizeof lazy);
  }
  void update(int a, int b, int c) { updateI(1, 1, size, a, b, c); }
  int query(int a) {return queryI(1, 1, size, a); }
};

int n, q;
map<int, int> compress;
vector<int> expand;
vector<PII> queries;
set<int> used;
set<int> visited;

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; i++) {
    int x, y;
    char dir;
    scanf("%d %d %c", &x, &y, &dir);
    int d = (dir == 'U') ? 0 : 1;
    if (used.count(x) == 0) {
      expand.push_back(x);
      used.insert(x);
    }
    queries.push_back(MP(x, d));
  }
  expand.push_back(0);
  sort(expand.begin(), expand.end());
  int sz = expand.size()-1;
  expand.push_back(n+1);
  ST yst(sz);
  ST xst(sz);
  for (int i = 1; i <= sz; i++) compress[expand[i]] = i;
  for (PII p: queries) {
    int x = compress[p.first];
    int y = sz+1-x;
    if (visited.count(x) != 0) printf("0\n");
    else {
      if (p.second) {
        int m = xst.query(x);
        printf("%d\n", p.first-expand[m]);
        yst.update(y, y+(x-m), y);
      } else {
        int m = yst.query(y);
        int expandm = n+1-expand[sz+1-m];
        int expandy = n+1-p.first;
        printf("%d\n", expandy-expandm);
        xst.update(x, x+(y-m), x);
      }
      visited.insert(x);
    }
  }
}


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

const int MAXN = 2E5 + 10;

int x[MAXN], y[MAXN];
char dir[MAXN];

struct SegTree {
	int st[MAXN * 4];
	void modify(int id, int l, int r, int qL, int qR, int val) {
		if (qL <= l && r <= qR) {
			st[id] = max(st[id], val);
		} else {
			int m = (l + r) >> 1;
			if (qL <= m) modify(id << 1, l, m, qL, qR, val);
			if (m < qR) modify(id << 1 | 1, m + 1, r, qL, qR, val);
		}
	}
	int query(int id, int l, int r, int p) {
		if (l == r) {
			return st[id];
		} else {
			int m = (l + r) >> 1;
			if (p <= m) return max(st[id], query(id << 1, l, m, p));
			else return max(st[id], query(id << 1 | 1, m + 1, r, p));
		}
	}
} up, lft;

int main() {
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n, q; cin >> n >> q;
	vector<int> xVal = { 0 }, yVal = { 0 };
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i] >> dir[i];
		xVal.push_back(x[i]), yVal.push_back(y[i]);
	}
	sort(xVal.begin(), xVal.end()), sort(yVal.begin(), yVal.end());
	xVal.resize(unique(xVal.begin(), xVal.end()) - xVal.begin());
	yVal.resize(unique(yVal.begin(), yVal.end()) - yVal.begin());
	for (int i = 0; i < q; i++) {
		x[i] = lower_bound(xVal.begin(), xVal.end(), x[i]) - xVal.begin();
		y[i] = lower_bound(yVal.begin(), yVal.end(), y[i]) - yVal.begin();
	}
	for (int i = 0; i < q; i++) {
		if (dir[i] == 'U') {
			int till = up.query(1, 1, n, x[i]);
			cout << yVal[y[i]] - yVal[till] << '\n';
			lft.modify(1, 1, n, till, y[i], x[i]);
		} else {
			int till = lft.query(1, 1, n, y[i]);
			cout << xVal[x[i]] - xVal[till] << '\n';
			up.modify(1, 1, n, till, x[i], y[i]);
		}
	//	bool d = dir[i] == 'U';
	//	int till = sts[d].query(1, 1, n, d ? x[i] : y[i]);
	//	cout << (d ? y[i] : x[i]) - till << '\n';
	//	sts[!d].modify(1, 1, n, till, d ? y[i] : x[i], d ? x[i] : y[i]);
	}
}