#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 200006
#define MOD 1000000007

struct Query {
	ll x;
	ll y;
	char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = max(tree[v], val);
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

void update_left(ll val, ll l, ll r)
{
	update_tree(left_tree, 0, val, l, r, 0, m - 1);
}

void update_up(ll val, ll l, ll r)
{
	update_tree(up_tree, 0, val, l, r, 0, m - 1);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
//		forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//		forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

//		cout << endl << pos << " " << qi.d << endl << endl;
		ll px = M[qi.x];
		ll py = M[qi.y];

//		cout << qi.d << "  " << qi.x << " " << qi.y << endl;

		if(qi.d == 'U') {

//			cout << "Get up: " << px << endl;
			ll mx_up = get_tree(up_tree, 0, px, 0, m - 1);
//			cout << pos << " " << m - mx_up << endl;
//			cout << "Update left: " << px << " " << mx_up << " " << py << endl;
			update_left(px, mx_up, py);

			update_up(py, px, px);

	//		cout << py << " " << mx_up << " | " << vs[py] << " " << vs[mx_up] << endl;

			cout << vs[py] - vs[mx_up] << endl;

/*			if(mx_up == 0) {
				cout << n + 1 - vs[pos] << endl;
			} else {
				cout << vs[m - mx_up - 1] - vs[pos] << endl;
			}*/
		} else {

//			cout << "Get left: " << py << endl;
			ll mx_left = get_tree(left_tree, 0, py, 0, m - 1);
//			cout << "Update up: " << py << "  " << mx_left << " " << px << endl;
			update_up(py, mx_left, px);

	//		cout << mx_left << " " << px << endl;

			update_left(px, py, py);
//			cout << mx_left << " " << pos << endl;

//			cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//			cout << vs
//			cout << vs[pos] - vs[mx_left] << endl;
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 400006
#define MOD 1000000007

struct Query {
	int x;
	int y;
	char d;
};

int left_tree[2 * MAXN];
int up_tree[2 * MAXN];

int m;

int get_tree(int *tree, int q)
{
	int res = 0;
	for(int p = m + q; p > 0; p /= 2) res = max(res, tree[p]);
	return res;
}

void update_tree(int *tree, int val, int l, int r)
{
	++r;
	for(l += m, r += m; l < r; l /= 2, r /= 2) {
		if(l & 1) { tree[l] = max(tree[l], val); ++l; }
		if(r & 1) { --r; tree[r] = max(tree[r], val); }
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	int q; cin >> q;

	vector<Query> qs(q);

	vector<int> vs;

	forr(i, q) {
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<int, int> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
		int px = M[qi.x];
		int py = M[qi.y];
		if(qi.d == 'U') {
			int mx_up = get_tree(up_tree, px);
			update_tree(left_tree, px, mx_up, py);
			update_tree(up_tree, py, px, px);
			cout << vs[py] - vs[mx_up] << endl;
		} else {
			int mx_left = get_tree(left_tree, py);
			update_tree(up_tree, py, mx_left, px);
			update_tree(left_tree, px, py, py);
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 400006
#define MOD 1000000007

struct Query {
	ll x;
	ll y;
	char d;
};

ll left_tree[4 * MAXN];
ll up_tree[4 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = max(tree[v], val);
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

void update_left(ll val, ll l, ll r)
{
	update_tree(left_tree, 0, val, l, r, 0, m - 1);
}

void update_up(ll val, ll l, ll r)
{
	update_tree(up_tree, 0, val, l, r, 0, m - 1);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
//		forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//		forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

//		cout << endl << pos << " " << qi.d << endl << endl;
		ll px = M[qi.x];
		ll py = M[qi.y];

//		cout << qi.d << "  " << qi.x << " " << qi.y << endl;

		if(qi.d == 'U') {

//			cout << "Get up: " << px << endl;
			ll mx_up = get_tree(up_tree, 0, px, 0, m - 1);
//			cout << pos << " " << m - mx_up << endl;
//			cout << "Update left: " << px << " " << mx_up << " " << py << endl;
			update_left(px, mx_up, py);

			update_up(py, px, px);

	//		cout << py << " " << mx_up << " | " << vs[py] << " " << vs[mx_up] << endl;

			cout << vs[py] - vs[mx_up] << endl;

/*			if(mx_up == 0) {
				cout << n + 1 - vs[pos] << endl;
			} else {
				cout << vs[m - mx_up - 1] - vs[pos] << endl;
			}*/
		} else {

//			cout << "Get left: " << py << endl;
			ll mx_left = get_tree(left_tree, 0, py, 0, m - 1);
//			cout << "Update up: " << py << "  " << mx_left << " " << px << endl;
			update_up(py, mx_left, px);

	//		cout << mx_left << " " << px << endl;

			update_left(px, py, py);
//			cout << mx_left << " " << pos << endl;

//			cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//			cout << vs
//			cout << vs[pos] - vs[mx_left] << endl;
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 200006
#define MOD 1000000007

struct Query {
    ll pos;
    char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
    if(tl == tr) {
        return tree[v];
    }

    ll vl = 2 * v + 1;
    ll vr = 2 * v + 2;

    tree[vl] = max(tree[vl], tree[v]);
    tree[vr] = max(tree[vr], tree[v]);

    ll med = tl + (tr - tl) / 2;
    if(q <= med) {
        return get_tree(tree, vl, q, tl, med);
    } else {
        return get_tree(tree, vr, q, med + 1, tr);
    }
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//  cout << val << " " << l << " " << r << endl;
    if(l > r) return;
    if(l == tl && r == tr) {
        tree[v] = max(tree[v], val);
        return;
    }

    ll vl = 2 * v + 1;
    ll vr = 2 * v + 2;

    tree[vl] = max(tree[vl], tree[v]);
    tree[vr] = max(tree[vr], tree[v]);

    ll med = tl + (tr - tl) / 2;

    update_tree(tree, vl, val, l, min(med, r), tl, med);
    update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    ll q; cin >> q;

    vector<Query> qs(q);

    vl vs;

    forr(i, q) {
        ll y;
        cin >> qs[i].pos >> y >> qs[i].d; qs[i].pos;
        vs.push_back(qs[i].pos);
    }

    vs.push_back(0);
    sort(vs.begin(), vs.end());
    auto it = unique(vs.begin(), vs.end());
    vs.resize(it - vs.begin());

    unordered_map<ll, ll> M;
    forr(i, vs.size()) {
        M[vs[i]] = i;
    }

    m = M.size();

    for(auto qi: qs) {
//      forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//      forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

        ll pos = M[qi.pos];

//      cout << endl << pos << " " << qi.d << endl << endl;

        if(qi.d == 'U') {
            ll mx_up = get_tree(up_tree, 0, pos, 0, m - 1);
//          cout << pos << " " << m - mx_up << endl;
            update_tree(left_tree, 0, pos, pos, m - mx_up - 1, 0, m - 1);
            update_tree(up_tree, 0, pos, pos, pos, 0, m - 1);
//          cout << mx_up << " " << vs[pos] << " " << vs[mx_up] << endl;

            if(mx_up == 0) {
                cout << n + 1 - vs[pos] << endl;
            } else {
                cout << vs[mx_up] - vs[pos] << endl;
            }
        } else {
            ll mx_left = get_tree(left_tree, 0, pos, 0, m - 1);
            update_tree(up_tree, 0, pos, mx_left, pos, 0, m - 1);
            update_tree(left_tree, 0, pos, pos, pos, 0, m - 1);
//          cout << mx_left << " " << pos << endl;

//          cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//          cout << vs
            cout << vs[pos] - vs[mx_left] << endl;
        }
    }

    return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 200006
#define MOD 1000000007

struct Query {
	ll pos;
	char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = val;
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].pos >> y >> qs[i].d; qs[i].pos;
		vs.push_back(qs[i].pos);
	}

	vs.push_back(0);
	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
//		forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//		forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

		ll pos = M[qi.pos];

//		cout << endl << pos << " " << qi.d << endl << endl;

		if(qi.d == 'U') {
			ll mx_up = get_tree(up_tree, 0, pos, 0, m - 1);
//			cout << pos << " " << m - mx_up << endl;
			update_tree(left_tree, 0, pos, pos, m - mx_up - 1, 0, m - 1);
//			cout << mx_up << " " << vs[pos] << " " << vs[mx_up] << endl;

			if(mx_up == 0) {
				cout << n + 1 - vs[pos] << endl;
			} else {
				cout << vs[mx_up] - vs[pos] << endl;
			}
		} else {
			ll mx_left = get_tree(left_tree, 0, pos, 0, m - 1);
			update_tree(up_tree, 0, pos, mx_left, pos, 0, m - 1);
//			cout << mx_left << " " << pos << endl;
//			cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//			cout << vs
			cout << vs[pos] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 400006
#define MOD 1000000007

struct Query {
	int x;
	int y;
	char d;
};

int left_tree[2 * MAXN];
int up_tree[2 * MAXN];

int m;

int get_tree(int *tree, int q)
{
	int res = 0;
	for(int p = m + q; p > 0; p /= 2) res = max(res, tree[p]);
	return res;
}

void update_tree(int *tree, int val, int l, int r)
{
	++r;
	for(l += m, r += m; l < r; l /= 2, r /= 2) {
		if(l & 1) { tree[l] = max(tree[l], val); ++l; }
		if(r & 1) { --r; tree[r] = max(tree[r], val); }
	}
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int n; cin >> n;
	int q; cin >> q;

	vector<Query> qs(q);

	vector<int> vs;
	vs.reserve(2 * q);

	forr(i, q) {
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<int, int> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto &qi: qs) {
		int px = M[qi.x];
		int py = M[qi.y];
		if(qi.d == 'U') {
			int mx_up = get_tree(up_tree, px);
			update_tree(left_tree, px, mx_up, py);
			update_tree(up_tree, py, px, px);
			cout << vs[py] - vs[mx_up] << endl;
		} else {
			int mx_left = get_tree(left_tree, py);
			update_tree(up_tree, py, mx_left, px);
			update_tree(left_tree, px, py, py);
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 400006
#define MOD 1000000007

struct Query {
	ll x;
	ll y;
	char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

ll get_tree(ll *tree, ll q)
{
	ll res = 0;
	for(ll p = m + q; p > 0; p /= 2) res = max(res, tree[p]);
	return res;
}

void update_tree(ll *tree, ll val, ll l, ll r)
{
	++r;
	for(l += m, r += m; l < r; l /= 2, r /= 2) {
		if(l & 1) { tree[l] = max(tree[l], val); ++l; }
		if(r & 1) { --r; tree[r] = max(tree[r], val); }
	}
}
/*
void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = max(tree[v], val);
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}
*/
void update_left(ll val, ll l, ll r)
{
	update_tree(left_tree, val, l, r);
//	update_tree(left_tree, 0, val, l, r, 0, m - 1);
}

void update_up(ll val, ll l, ll r)
{
	update_tree(up_tree, val, l, r);
	//update_tree(up_tree, 0, val, l, r, 0, m - 1);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
		ll px = M[qi.x];
		ll py = M[qi.y];
		if(qi.d == 'U') {
			//ll mx_up = get_tree(up_tree, 0, px, 0, m - 1);
			ll mx_up = get_tree(up_tree, px);
			update_left(px, mx_up, py);
			update_up(py, px, px);
			cout << vs[py] - vs[mx_up] << endl;
		} else {
			//ll mx_left = get_tree(left_tree, 0, py, 0, m - 1);
			ll mx_left = get_tree(left_tree, py);
			update_up(py, mx_left, px);
			update_left(px, py, py);
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <deque>
#include <ctime>
#include <cstring>
#include <unordered_map>

//#include <bits/stdc++.h>

using namespace std;

#define fr first
#define sd second
#define pb push_back
#define mp make_pair

#define endl '\n'

#define forr(i, n) for(ll (i) = 0LL; (i) < (n); (i)++)
#define mp3(a, b, c) mp(a, mp(b, c))

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plll;
typedef vector < vector < double > > vvd;
typedef vector < double > vd;
typedef vector < pair < double, double> > vdd;
typedef vector < vector < long long > > vvl;
typedef vector < long long > vl;
typedef vector < pll > vll;

int INT_MAX_VAL = (int)  0x3F3F3F3F;
int INT_MIN_VAL = (int) -0x3F3F3F3F;
ll LONG_MAX_VAL = (ll)   0x3F3F3F3F3F3F3F3F;
ll LONG_MIN_VAL = (ll)  -0x3F3F3F3F3F3F3F3F;

#define MAXN 400006
#define MOD 1000000007

struct Query {
	ll x;
	ll y;
	char d;
};

ll left_tree[2 * MAXN];
ll up_tree[2 * MAXN];

int m;

ll get_tree(ll *tree, ll v, ll q, ll tl, ll tr)
{
	if(tl == tr) {
		return tree[v];
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;
	if(q <= med) {
		return get_tree(tree, vl, q, tl, med);
	} else {
		return get_tree(tree, vr, q, med + 1, tr);
	}
}

void update_tree(ll *tree, ll v, ll val, ll l, ll r, ll tl, ll tr)
{
//	cout << val << " " << l << " " << r << endl;
	if(l > r) return;
	if(l == tl && r == tr) {
		tree[v] = max(tree[v], val);
		return;
	}

	ll vl = 2 * v + 1;
	ll vr = 2 * v + 2;

	tree[vl] = max(tree[vl], tree[v]);
	tree[vr] = max(tree[vr], tree[v]);
	tree[v] = 0;

	ll med = tl + (tr - tl) / 2;

	update_tree(tree, vl, val, l, min(med, r), tl, med);
	update_tree(tree, vr, val, max(med + 1, l), r, med + 1, tr);
}

void update_left(ll val, ll l, ll r)
{
	update_tree(left_tree, 0, val, l, r, 0, m - 1);
}

void update_up(ll val, ll l, ll r)
{
	update_tree(up_tree, 0, val, l, r, 0, m - 1);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n; cin >> n;
	ll q; cin >> q;

	vector<Query> qs(q);

	vl vs;

	forr(i, q) {
		ll y;
		cin >> qs[i].x >> qs[i].y >> qs[i].d;
		vs.push_back(qs[i].x);
		vs.push_back(qs[i].y);
	}

	vs.push_back(0);

	sort(vs.begin(), vs.end());
	auto it = unique(vs.begin(), vs.end());
	vs.resize(it - vs.begin());

	unordered_map<ll, ll> M;
	forr(i, vs.size()) {
		M[vs[i]] = i;
	}

	m = M.size();

	for(auto qi: qs) {
//		forr(i, 2 * m) cout << left_tree[i] << " "; cout << endl;
//		forr(i, 2 * m) cout << up_tree[i] << " "; cout << endl;

//		cout << endl << pos << " " << qi.d << endl << endl;
		ll px = M[qi.x];
		ll py = M[qi.y];

//		cout << qi.d << "  " << qi.x << " " << qi.y << endl;

		if(qi.d == 'U') {

//			cout << "Get up: " << px << endl;
			ll mx_up = get_tree(up_tree, 0, px, 0, m - 1);
//			cout << pos << " " << m - mx_up << endl;
//			cout << "Update left: " << px << " " << mx_up << " " << py << endl;
			update_left(px, mx_up, py);

			update_up(py, px, px);

	//		cout << py << " " << mx_up << " | " << vs[py] << " " << vs[mx_up] << endl;

			cout << vs[py] - vs[mx_up] << endl;

/*			if(mx_up == 0) {
				cout << n + 1 - vs[pos] << endl;
			} else {
				cout << vs[m - mx_up - 1] - vs[pos] << endl;
			}*/
		} else {

//			cout << "Get left: " << py << endl;
			ll mx_left = get_tree(left_tree, 0, py, 0, m - 1);
//			cout << "Update up: " << py << "  " << mx_left << " " << px << endl;
			update_up(py, mx_left, px);

	//		cout << mx_left << " " << px << endl;

			update_left(px, py, py);
//			cout << mx_left << " " << pos << endl;

//			cout << mx_left << " " << vs[mx_left] << " " << vs[pos] << endl;
//			cout << vs
//			cout << vs[pos] - vs[mx_left] << endl;
			cout << vs[px] - vs[mx_left] << endl;
		}
	}

	return 0;
}


#include <cstdio>
#include <map>
using namespace std;

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            printf("%d\n", row - U.min(col));

            L.add(1, row, col);
            U.add(col, col, row);
        }

        else if (dir == 'L')
        {
            printf("%d\n", col - L.min(row));

            U.add(1, col, row);
            L.add(row, row, col);
        }
    }

    return 0;
}


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

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    int a, b, value;

    void _add(int p, int q, int v)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            _add(p, m, v * 2);
        if (b > m)
            _add(m + 1, q, v * 2 + 1);
    }

    void add(int _a, int _b, int _value)
    {
        a = _a;
        b = _b;
        value = _value;
        _add(0, i0 - 1, 1);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

set<int> usedL, usedU;

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            int eaten;
            if (usedU.find(col) != usedU.end())
                eaten = 0;
            else
            {
                usedU.insert(col);
                eaten = row - U.min(col);
            }

            printf("%d\n", eaten);
            L.add(row - eaten + 1, row, col);
        }

        else if (dir == 'L')
        {
            int eaten;
            if (usedL.find(row) != usedL.end())
                eaten = 0;
            else
            {
                eaten = col - L.min(row);
                usedL.insert(row);
            }

            printf("%d\n", eaten);
            U.add(col - eaten + 1, col, row);
        }
    }

    return 0;
}


#include <cstdio>
#include <map>
using namespace std;

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            int eaten = row - U.min(col);
            printf("%d\n", eaten);

            L.add(row - eaten + 1, row, col);
            U.add(col, col, row);
        }

        else if (dir == 'L')
        {
            int eaten = col - L.min(row);
            printf("%d\n", eaten);

            U.add(col - eaten + 1, col, row);
            L.add(row, row, col);
        }
    }

    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

struct node
{
    int from, to, value;
    node *left, *right;

    node(int _from, int _to)
        : from {_from}, to {_to}, value {0},
          left {NULL}, right {NULL}
    {
    }

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

struct tree
{
    node* root;

    tree(int n)
    {
        int size = 16;
        while (size <= n)
            size *= 2;

        root = new node(0, size - 1);
    }

    ~tree()
    {
        delete root;
    }

    void add(int a, int b, int value, node *curr)
    {
        int from = curr -> from;
        int to = curr -> to;

        if (from >= a && to <= b)
        {
            curr -> value = std::max(curr -> value, value);
            return;
        }

        int m = (from + to) / 2;
        if (a <= m)
        {
            if (curr -> left == NULL)
                curr -> left = new node(from, m);

            add(a, b, value, curr -> left);
        }
        if (b > m)
        {
            if (curr -> right == NULL)
                curr -> right = new node(m + 1, to);

            add(a, b, value, curr -> right);
        }
    }

    void add(int a, int b, int value)
    {
        add(a, b, value, root);
    }

    int max(int x, node *curr, int value)
    {
        if (curr -> left != NULL && x <= (curr -> left) -> to)
        {
            curr = curr -> left;
            value = std::max(value, curr -> value);
            return max(x, curr, value);
        }
        else if (curr -> right != NULL && x >= (curr -> right) -> from)
        {
            curr = curr -> right;
            value = std::max(value, curr -> value);
            return max(x, curr, value);
        }

        return value;
    }

    int max(int x)
    {
        return max(x, root, root -> value);
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            int eaten = row - U.max(col);
            printf("%d\n", eaten);

            L.add(row - eaten + 1, row, col);
            U.add(col, col, row);
        }

        else if (dir == 'L')
        {
            int eaten = col - L.max(row);
            printf("%d\n", eaten);

            U.add(col - eaten + 1, col, row);
            L.add(row, row, col);
        }
    }

    return 0;
}


#include <cstdio>
#include <map>
using namespace std;

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            L.add(1, row, col);
            U.add(row, row, col);
            printf("%d\n", row - U.min(col));
        }

        else if (dir == 'L')
        {
            U.add(1, col, row);
            L.add(col, col, row);
            printf("%d\n", col - L.min(row));
        }
    }

    return 0;
}


#include <cstdio>
#include <unordered_map>
using namespace std;

struct tree
{
    unordered_map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            int eaten = row - U.min(col);
            printf("%d\n", eaten);

            L.add(row - eaten + 1, row, col);
            U.add(col, col, row);
        }

        else if (dir == 'L')
        {
            int eaten = col - L.min(row);
            printf("%d\n", eaten);

            U.add(col - eaten + 1, col, row);
            L.add(row, row, col);
        }
    }

    return 0;
}


#include <cstdio>
#include <map>
using namespace std;

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            L.add(1, row, col);
            printf("%d\n", row - U.min(col));
        }

        else if (dir == 'L')
        {
            U.add(1, col - 1, row);
            printf("%d\n", col - L.min(row));
        }
    }

    return 0;
}


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

struct tree
{
    map <int, int> M;
    int i0;

    tree (int n)
    {
        i0 = 32;
        while (i0 <= n)
            i0 *= 2;
    }

    void add(int p, int q, int a, int b, int v, int value)
    {
        if (p >= a && q <= b)
        {
            auto iter = M.find(v);

            int old = iter == M.end() ? 0 : iter -> second;
            M[v] = max(old, value);

            return;
        }

        int m = (p + q) / 2;
        if (a <= m)
            add(p, m, a, b, v * 2, value);
        if (b > m)
            add(m + 1, q, a, b, v * 2 + 1, value);
    }

    void add(int a, int b, int value)
    {
        add(0, i0 - 1, a, b, 1, value);
    }

    int min(int x)
    {
        int answer = 0;

        x += i0;
        while (x >= 1)
        {
            auto iter = M.find(x);
            if (iter != M.end())
                answer = max(answer, iter -> second);

            x /= 2;
        }

        return answer;
    }
};

set<int> usedL, usedU;

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);

    tree U(n), L(n);

    while (q--)
    {
        int col, row;
        char dir;
        scanf ("%d %d %c", &col, &row, &dir);

        if (dir == 'U')
        {
            int eaten;
            if (usedU.find(col) != usedU.end())
                eaten = 0;
            else
            {
                usedU.insert(col);
                eaten = row - U.min(col);
            }

            printf("%d\n", eaten);

            L.add(row - eaten + 1, row, col);
        }

        else if (dir == 'L')
        {
            int eaten;
            if (usedL.find(row) != usedL.end())
                eaten = 0;
            else
            {
                eaten = col - L.min(row);
                usedL.insert(row);
            }

            printf("%d\n", eaten);

            U.add(col - eaten + 1, col, row);
            L.add(row, row, col);
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
    }
    return;
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[1]);
  build(1, 0, vyk - 1, tree[0]);
  for (int i = 0; i < q; ++i) {
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[0]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll, rr, val, tree[1]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[1]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll, rr, val, tree[0]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;
int ff[N][2];

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
    }
    return;
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[1]);
  build(1, 0, vyk - 1, tree[0]);
  for (int i = 0; i < q; ++i) {
    if (ff[rkx[x[i]]][d[i]]) {
      puts("0");
      continue;
    }
    ff[rkx[x[i]]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[0]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll + 1, rr, val, tree[1]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[1]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll + 1, rr, val, tree[0]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;
int ff[N][2];

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
      return;
    }
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (ll < l || ll > r) return 0;
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[1]);
  build(1, 0, vyk - 1, tree[0]);
  for (int i = 0; i < q; ++i) {
    if (ff[rkx[x[i]]][d[i]]) {
      puts("0");
      continue;
    }
    ff[rkx[x[i]]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[0]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll + 1, rr, val, tree[1]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[1]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll + 1, rr, val, tree[0]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[20];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int nx, ny;
bool ff[N][2];

int treex[N * 4], treey[N * 4];

void update(int p, int l, int r, int ll, int rr, int v, int *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    tr[p] = max(tr[p], v);
    return;
  }
  int mid = (l + r) >> 1;
  update(p * 2, l, mid, ll, rr, v, tr);
  update(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
}

int query(int p, int l, int r, int x, int *tr) {
  if (x < l || x > r) return -1;
  if (l == r) return tr[p];
  int mid = (l + r) >> 1;
  int res = tr[p];
  res = max(res, query(p * 2, l, mid, x, tr));
  res = max(res, query(p * 2 + 1, mid + 1, r, x, tr));
  return res;
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  nx = vx.size();
  for (int i = 0; i < nx; ++i) {
    rkx[vx[i]] = i;
  }
  ny = vy.size();
  for (int i = 0; i < ny; ++i) {
    rky[vy[i]] = i;
  }
  for (int i = 0; i < q; ++i) {
    x[i] = rkx[x[i]];
    y[i] = rky[y[i]];
  }
  for (int i = 0; i < q; ++i) {
    if (ff[x[i]][d[i]]) {
      puts("0");
      continue;
    }
    ff[x[i]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, ny - 1, y[i], treey);
      printf("%d\n", vx[x[i]] - vx[ll]);
      update(1, 0, nx - 1, ll, x[i], y[i], treex);
    }
    else {
      int ll = query(1, 0, nx - 1, x[i], treex);
      printf("%d\n", vy[y[i]] - vy[ll]);
      update(1, 0, ny - 1, ll, y[i], x[i], treey);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int n, q;
char s[20];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int nx, ny;
bool ff[N][2];

struct node {
  int lazyval;
  int mx;
} treex[N * 4], treey[N * 4];

void update(int p, int l, int r, int ll, int rr, int v, node *tr);

void pushdown(int p, int l, int r, node *tr) {
  if (tr[p].lazyval <= 0) return;
  int mid = (l + r) >> 1;
  update(p * 2, l, mid, l, mid, tr[p].lazyval, tr);
  update(p * 2 + 1, mid + 1, r, mid + 1, r, tr[p].lazyval, tr);
  tr[p].lazyval = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.lazyval = 0;
  res.mx = max(a.mx, b.mx);
  return res;
}

void update(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    tr[p].lazyval = max(tr[p].lazyval, v);
    tr[p].mx = max(tr[p].mx, v);
    return;
  }
  pushdown(p, l, r, tr);
  int mid = (l + r) >> 1;
  update(p * 2, l, mid, ll, rr, v, tr);
  update(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int x, node *tr) {
  if (x < l || x > r) return -1;
  if (l == r) return tr[p].mx;
  pushdown(p, l, r, tr);
  int mid = (l + r) >> 1;
  if (x <= mid) return query(p * 2, l, mid, x, tr);
  else return query(p * 2 + 1, mid + 1, r, x, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  sort(vy.begin(), vy.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  vy.erase(unique(vx.begin(), vx.end()), vx.end());
  nx = vx.size();
  for (int i = 0; i < nx; ++i) {
    rkx[vx[i]] = i;
  }
  ny = vy.size();
  for (int i = 0; i < ny; ++i) {
    rky[vy[i]] = i;
  }
  for (int i = 0; i < q; ++i) {
    x[i] = rkx[x[i]];
    y[i] = rky[y[i]];
  }
  for (int i = 0; i < q; ++i) {
    if (ff[x[i]][d[i]]) {
      puts("0");
      continue;
    }
    ff[x[i]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, ny, y[i], treey);
      printf("%d\n", vx[x[i]] - vx[ll]);
      update(1, 0, nx, ll, x[i], y[i], treex);
    }
    else {
      int ll = query(1, 0, nx, x[i], treex);
      printf("%d\n", vy[y[i]] - vy[ll]);
      update(1, 0, ny, ll, y[i], x[i], treey);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;
int ff[N][2];

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
      return;
    }
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (ll < l || ll > r) return 0;
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[0]);
  build(1, 0, vyk - 1, tree[1]);
  for (int i = 0; i < q; ++i) {
    if (ff[rkx[x[i]]][d[i]]) {
      puts("0");
      continue;
    }
    ff[rkx[x[i]]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[1]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll, rr, val, tree[0]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[0]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll, rr, val, tree[1]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;
int ff[N][2];

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
    }
    return;
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[1]);
  build(1, 0, vyk - 1, tree[0]);
  for (int i = 0; i < q; ++i) {
    if (ff[x[i]][d[i]]) {
      puts("0");
      continue;
    }
    ff[x[i]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[0]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll, rr, val, tree[1]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[1]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll, rr, val, tree[0]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 10;

int n, q;
char s[20];
int x[N], y[N], d[N];
bool ff[N][2];
vector<int> vx, vy;
int cntx, cnty;
unordered_map<int, int> rkx, rky;

struct node {
  int mx;
  bool lazy;
} tree[2][N * 4];

node mrg(node &a, node &b) {
  node res;
  res.lazy = 0;
  res.mx = max(a.mx, b.mx);
  return res;
}

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].lazy) return;
  tr[p * 2 + 1].lazy = tr[p * 2].lazy = 1;
  tr[p * 2 + 1].mx = tr[p * 2].mx = tr[p].mx;
  tr[p].lazy = 0;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (rr < l || ll > r) return;
  if (ll <= l && rr >= r) {
    if (tr[p].lazy) {
      tr[p].mx = max(tr[p].mx, v);
      return;
    }
    else {
      if (tr[p].mx < v) {
        tr[p].lazy = 1;
        tr[p].mx = v;
        return;
      }
    }
  }
  if (l == r) return;
  pushdown(p, l, r, tr);
  int mid = (l + r) >> 1;
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int x, node *tr) {
  if (l <= x && x <= r && tr[p].lazy) {
    return tr[p].mx;
  }
  if (l == x && r == x) {
    return tr[p].mx;
  }
  pushdown(p, l, r, tr);
  int mid = (l + r) >> 1;
  if (x > mid) {
    return query(p * 2 + 1, mid + 1, r, x, tr);
  }
  else {
    return query(p * 2, l, mid, x, tr);
  }
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  cntx = vx.size();
  for (int i = 0; i < cntx; ++i) {
    rkx[vx[i]] = i;
  }
  cnty = vy.size();
  for (int i = 0; i < cnty; ++i) {
    rky[vy[i]] = i;
  }
  for (int i = 0; i < q; ++i) {
    x[i] = rkx[x[i]];
    y[i] = rky[y[i]];
  }
  for (int i = 0; i < q; ++i) {
    if (ff[x[i]][d[i]]) {
      puts("0");
      continue;
    }
    ff[x[i]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, cnty - 1, y[i], tree[1]);
      printf("%d\n", vx[x[i]] - vx[ll]);
      setall(1, 0, cntx - 1, ll, x[i], y[i], tree[0]);
    }
    else {
      int ll = query(1, 0, cntx - 1, x[i], tree[0]);
      printf("%d\n", vy[y[i]] - vy[ll]);
      setall(1, 0, cnty - 1, ll, y[i], x[i], tree[1]);
    }
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, q, x, y;
map<int, pair<char, int> > mp;

int query() {
  char c;
  scanf("%d%d%*c%c", &x, &y, &c);
  auto b = mp.lower_bound(x);
  if (b->first == x) return 0;
  if (c == 'L') --b;
  int ans = abs(b->first - x);
  if (b->second.first == c) ans += b->second.second;
  mp[x] = {c, ans};
  return ans;
}

int main() {
  scanf("%d%d", &n, &q);
  mp[0] = {'U', 0};
  mp[n + 1] = {'L', 0};
  for (; q; --q)
    printf("%d\n", query());
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define out(x) cerr << #x"=" << x << endl

const int N = 2e5 + 10;

int n, q;
char s[10];
int x[N], y[N], d[N];
vector<int> vx, vy;
unordered_map<int, int> rkx, rky;
int vxk, vyk;
int ff[N][2];

struct node {
  int f, v;
} tree[2][N * 4];

void pushdown(int p, int l, int r, node *tr) {
  if (!tr[p].f) return;
  tr[p * 2].f = 1;
  tr[p * 2].v = tr[p].v;
  tr[p * 2 + 1].f = 1;
  tr[p * 2 + 1].v = tr[p].v;
  tr[p].f = 0;
}

node mrg(node &a, node &b) {
  node res;
  res.f = 0;
  res.v = max(a.v, b.v);
  return res;
}

void setall(int p, int l, int r, int ll, int rr, int v, node *tr) {
  if (ll > r || rr < l) return;
  if (ll <= l && rr >= r) {
    if (tr[p].f || tr[p].v < v) {
      tr[p].f = 1;
      tr[p].v = max(tr[p].v, v);
    }
    return;
  }
  if (l == r)
    return;
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  setall(p * 2, l, mid, ll, rr, v, tr);
  setall(p * 2 + 1, mid + 1, r, ll, rr, v, tr);
  tr[p] = mrg(tr[p * 2], tr[p * 2 + 1]);
}

int query(int p, int l, int r, int ll, node *tr) {
  if (l <= ll && r >= ll && tr[p].f) {
    return tr[p].v;
  }
  int mid = (l + r) >> 1;
  pushdown(p, l, r, tr);
  if (ll <= mid) {
    return query(p * 2, l, mid, ll, tr);
  }
  else {
    return query(p * 2 + 1, mid + 1, r, ll, tr);
  }
}

void build(int p, int l, int r, node *tr) {
  if (l == r) {
    tr[p].f = 1;
    return;
  }
  int mid = (l + r) >> 1;
  build(p * 2, l, mid, tr);
  build(p * 2 + 1, mid + 1, r, tr);
}

int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < q; ++i) {
    scanf("%d%d%s", x + i, y + i, s);
    d[i] = (s[0] == 'L');
    vx.push_back(x[i]);
    vy.push_back(y[i]);
  }
  vx.push_back(0);
  vy.push_back(0);
  sort(vx.begin(), vx.end());
  vx.erase(unique(vx.begin(), vx.end()), vx.end());
  sort(vy.begin(), vy.end());
  vy.erase(unique(vy.begin(), vy.end()), vy.end());
  vxk = vx.size();
  for (int i = 0; i < vxk; ++i) {
    rkx[vx[i]] = i;
  }
  vyk = vy.size();
  for (int i = 0; i < vyk; ++i) {
    rky[vy[i]] = i;
  }
  build(1, 0, vxk - 1, tree[1]);
  build(1, 0, vyk - 1, tree[0]);
  for (int i = 0; i < q; ++i) {
    if (ff[rkx[x[i]]][d[i]]) {
      puts("0");
      continue;
    }
    ff[rkx[x[i]]][d[i]] = 1;
    if (d[i]) {
      // left
      int ll = query(1, 0, vyk - 1, rky[y[i]], tree[0]);
      int rr = rkx[x[i]];
      printf("%d\n", vx[rr] - vx[ll]);
      int val = rky[y[i]];
      setall(1, 0, vxk - 1, ll, rr, val, tree[1]);
    }
    else {
      int ll = query(1, 0, vxk - 1, rkx[x[i]], tree[1]);
      int rr = rky[y[i]];
      printf("%d\n", vy[rr] - vy[ll]);
      int val = rkx[x[i]];
      setall(1, 0, vyk - 1, ll, rr, val, tree[0]);
    }
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define MIN     (1<<30)
#define MAX     200000
#define D(x)    printf("-> %d\n",x)

pair<int,int> P[MAX+10];
char dir[MAX+10];
set<int> S;
map<int,int> M, IM;

int tree[3][MAX+10];
bool rpt[3][MAX+10];
// 0 -> Column Segment
// 1 -> Row Segment

void update(int idx, int st, int ed, int pos, int val, int N)
{
    if(st == ed)
    {
        tree[N][idx] = val;
        return;
    }

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(pos <= mid) update(l,st,mid,pos,val,N);
    else update(r,mid+1,ed,pos,val,N);

    tree[N][idx] = min(tree[N][l], tree[N][r]);
}

int query(int idx, int st, int ed ,int i, int j, int N)
{
    if(st == i && ed == j) return tree[N][idx];

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(j <= mid) return query(l,st,mid,i,j,N);
    else if(i > mid) return query(r,mid+1,ed,i,j,N);
    else return min(query(l,st,mid,i,mid,N), query(r,mid+1,ed,mid+1,j,N));
}

int main()
{
    //freopen("c:\\Users\\User\\Desktop\\in.txt", "r", stdin);

    int i, j, k, n, q, idx = 0, r, c, lo, hi, mid;
    char ch;

    scanf("%d %d", &n, &q);
    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &P[i].second, &P[i].first, &dir[i]);
        S.insert(P[i].first);
    }

    M[idx] = IM[idx] = idx;
    for(set<int>::iterator it = S.begin(); it != S.end(); it++)
        M[*it] = ++idx, IM[idx] = *it;

    M[n+1] = ++idx;
    IM[idx] = n+1;

    update(1,0,idx,0,0,0);
    update(1,0,idx,idx,0,1);

    for(i = 1; i <= idx; i++)
    {
        update(1,0,idx,i,n+1-IM[i],0);
        update(1,0,idx,i,IM[i], 1);
    }

    for(i = 1; i <= q; i++)
    {
        r = P[i].first;
        c = P[i].second;
        ch = dir[i];

        if(ch == 'U')
        {
            lo = 0;
            hi = M[r]-1;
            while(lo != hi)
            {
                mid = lo + (hi-lo+1)/2;
                if(query(1,0,idx,mid,hi,0) <= c) lo = mid;
                else hi = mid-1;
            }

            if(!rpt[0][M[r]] && !rpt[1][M[r]])
            {
                printf("%d\n", r-IM[lo]-1 + !rpt[1][M[r]]);
                update(1,0,idx,M[r],IM[lo]+1,1);
                rpt[0][M[r]] = true;
            }
            else puts("0");
        }

        else
        {
            lo = M[r]+1;
            hi = idx;

            while(lo != hi)
            {
                mid = (lo+hi)/2;
                if(query(1,0,idx,lo,mid,1) <= r) hi = mid;
                else lo = mid+1;
            }

            if(!rpt[1][M[r]] && !rpt[0][M[r]])
            {
                printf("%d\n", c - (n+1-IM[lo]) -1 + !rpt[0][M[r]]);
                update(1,0,idx,M[r], n +1-IM[lo]+1, 0);
                rpt[1][M[r]] = true;
            }
            else puts("0");
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf     (1<<30)
#define MAX     200010
#define D(x)    printf("-> %d\n",x)

typedef long long int LL;

pair<int,int> P[MAX+10];
char dir[MAX+10];
set<int> S;
map<int,int> M, IM;

int tree[3][MAX+10];
bool rpt[3][MAX+10];
// 0 -> Column Segment
// 1 -> Row Segment

void update(int idx, int st, int ed, int pos, int val, int N)
{
    if(st == ed)
    {
        tree[N][idx] = val;
        return;
    }

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(pos <= mid) update(l,st,mid,pos,val,N);
    else update(r,mid+1,ed,pos,val,N);

    tree[N][idx] = min(tree[N][l], tree[N][r]);
}

int query(int idx, int st, int ed ,int i, int j, int N)
{
    if(st == i && ed == j) return tree[N][idx];

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(j <= mid) return query(l,st,mid,i,j,N);
    else if(i > mid) return query(r,mid+1,ed,i,j,N);
    else return min(query(l,st,mid,i,mid,N), query(r,mid+1,ed,mid+1,j,N));
}

int main()
{
    //freopen("c:\\Users\\User\\Desktop\\in.txt", "r", stdin);

    int i, j, k, n, q, idx = 0, r, c;
    LL lo, hi, mid;
    char ch;

    scanf("%d %d", &n, &q);
    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &P[i].second, &P[i].first, &dir[i]);
        S.insert(P[i].first);
    }

    M[idx] = IM[idx] = idx;
    for(set<int>::iterator it = S.begin(); it != S.end(); it++)
        M[*it] = ++idx, IM[idx] = *it;

    M[n+1] = ++idx;
    IM[idx] = n+1;

    update(1,0,idx,0,0,0);
    update(1,0,idx,idx,0,1);

    for(i = 1; i <= idx; i++)
    {
        update(1,0,idx,i,n+1-IM[i],0);
        update(1,0,idx,i,IM[i], 1);
    }

    for(i = 1; i <= q; i++)
    {
        r = P[i].first;
        c = P[i].second;
        ch = dir[i];

        if(ch == 'U')
        {
            lo = 0;
            hi = M[r]-1;
            while(lo != hi)
            {
                mid = lo + (hi-lo+1)/2;
                if(query(1,0,idx,mid,hi,0) <= c) lo = mid;
                else hi = mid-1;
            }

            if(!rpt[0][M[r]] && !rpt[1][M[r]])
            {
                printf("%d\n", r-IM[lo]);
                update(1,0,idx,M[r],IM[lo]+1,1);
                rpt[0][M[r]] = true;
            }
            else puts("0");
        }

        else
        {
            lo = M[r]+1;
            hi = idx;

            while(lo != hi)
            {
                mid = (lo+hi)/2;
                if(query(1,0,idx,lo,mid,1) <= r) hi = mid;
                else lo = mid+1;
            }

            if(!rpt[1][M[r]] && !rpt[0][M[r]])
            {
                printf("%d\n", c - (n+1-IM[lo]));
                update(1,0,idx,M[r], n +1-IM[lo]+1, 0);
                rpt[1][M[r]] = true;
            }
            else puts("0");
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf     (1<<30)
#define MAX     200010
#define D(x)    printf("-> %d\n",x)

typedef long long int LL;

pair<int,int> P[MAX+10];
char dir[MAX+10];
set<int> S;
map<int,int> M, IM;

int tree[3][4*MAX+10];
bool rpt[3][4*MAX+10];
// 0 -> Column Segment
// 1 -> Row Segment

void update(int idx, int st, int ed, int pos, int val, int N)
{
    if(st == ed)
    {
        tree[N][idx] = val;
        return;
    }

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(pos <= mid) update(l,st,mid,pos,val,N);
    else update(r,mid+1,ed,pos,val,N);

    tree[N][idx] = min(tree[N][l], tree[N][r]);
}

int query(int idx, int st, int ed ,int i, int j, int N)
{
    if(st == i && ed == j) return tree[N][idx];

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(j <= mid) return query(l,st,mid,i,j,N);
    else if(i > mid) return query(r,mid+1,ed,i,j,N);
    else return min(query(l,st,mid,i,mid,N), query(r,mid+1,ed,mid+1,j,N));
}

int main()
{
    //freopen("c:\\Users\\User\\Desktop\\in.txt", "r", stdin);

    int i, j, k, n, q, idx = 0, r, c;
    LL lo, hi, mid;
    char ch;

    scanf("%d %d", &n, &q);
    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &P[i].second, &P[i].first, &dir[i]);
        S.insert(P[i].first);
    }

    M[idx] = IM[idx] = idx;
    for(set<int>::iterator it = S.begin(); it != S.end(); it++)
        M[*it] = ++idx, IM[idx] = *it;

    M[n+1] = ++idx;
    IM[idx] = n+1;

    update(1,0,idx,0,0,0);
    update(1,0,idx,idx,0,1);

    for(i = 1; i <= idx; i++)
    {
        update(1,0,idx,i,n+1-IM[i],0);
        update(1,0,idx,i,IM[i], 1);
    }

    for(i = 1; i <= q; i++)
    {
        r = P[i].first;
        c = P[i].second;
        ch = dir[i];

        if(ch == 'U')
        {
            lo = 0;
            hi = M[r]-1;
            while(lo != hi)
            {
                mid = lo + (hi-lo+1)/2;
                if(query(1,0,idx,mid,hi,0) <= c) lo = mid;
                else hi = mid-1;
            }

            if(!rpt[0][M[r]] && !rpt[1][M[r]])
            {
                printf("%d\n", r-IM[lo]);
                update(1,0,idx,M[r],IM[lo]+1,1);
                rpt[0][M[r]] = true;
            }
            else puts("0");
        }

        else
        {
            lo = M[r]+1;
            hi = idx;

            while(lo != hi)
            {
                mid = (lo+hi)/2;
                if(query(1,0,idx,lo,mid,1) <= r) hi = mid;
                else lo = mid+1;
            }

            if(!rpt[1][M[r]] && !rpt[0][M[r]])
            {
                printf("%d\n", c - (n+1-IM[lo]));
                update(1,0,idx,M[r], n +1-IM[lo]+1, 0);
                rpt[1][M[r]] = true;
            }
            else puts("0");
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define D(x)    printf("-> %d\n", x)

map<int,int>Rpt;

struct node{
    int lazy, max;
    node *l,*r;
    node():lazy(0),max(0),l(0),r(0){}
};

void update(node *cur, int st, int ed, int i, int j, int val)
{
    if(st == i && ed == j)
    {
        cur->lazy = max(cur->lazy, val);
        cur->max = cur->lazy;
        return;
    }

    int mid = (st+ed)/2;
    if(!cur->l) cur->l = new node;
    if(!cur->r) cur->r = new node;

    if(cur->lazy)
    {
        cur->l->lazy = max(cur->lazy, cur->l->lazy);
        cur->r->lazy = max(cur->lazy, cur->r->lazy);
        cur->lazy = 0;
    }

    if(j <= mid) update(cur->l, st,mid,i,j,val);
    else if(i > mid) update(cur->r,mid+1,ed,i,j,val);
    else update(cur->l,st,mid,i,mid,val), update(cur->r,mid+1,ed,mid+1,j,val);

    cur->max = max(cur->l->max, cur->r->max);
}

int query(node *cur, int st, int ed, int pos)
{
    if(st == ed) return max(cur->lazy, cur->max);

    int mid = (st+ed)/2;
    if(!cur->l) cur->l = new node;
    if(!cur->r) cur->r = new node;

    if(cur->lazy)
    {
        cur->l->lazy = max(cur->lazy, cur->l->lazy);
        cur->r->lazy = max(cur->lazy, cur->r->lazy);
        cur->lazy = 0;
    }

    if(pos <= mid) return query(cur->l,st,mid,pos);
    return query(cur->r,mid+1,ed,pos);
}

int main()
{
    //freopen("in.txt","r",stdin);
    int i, j, k, n, q, r, c, rmx;
    char ch;

    node *Cseg, *Rseg;
    Cseg = new node;
    Rseg = new node;

    scanf("%d %d", &n, &q);
    update(Cseg,1,n,1,n,0);
    update(Rseg,1,n,1,n,0);

    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &r, &c, &ch);
        swap(r,c);

        if(Rpt[r])
        {
            puts("0");
            continue;
        }
        Rpt[r] = 1;

        if(ch == 'U')
        {
            rmx = query(Cseg,1,n,c);
            printf("%d\n", r-rmx);
            update(Rseg,1,n,rmx+1,r,c);
        }
        else
        {
            rmx = query(Rseg,1,n,r);
            printf("%d\n", c-rmx);
            update(Cseg,1,n,rmx+1,c,r);
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf     (1<<30)
#define MAX     300000
#define D(x)    printf("-> %d\n",x)

typedef long long int LL;

pair<int,int> P[MAX+10];
char dir[MAX+10];
set<int> S;
map<int,int> M, IM;

int tree[3][MAX+10];
bool rpt[3][MAX+10];
// 0 -> Column Segment
// 1 -> Row Segment

void update(int idx, int st, int ed, int pos, int val, int N)
{
    if(st == ed)
    {
        tree[N][idx] = val;
        return;
    }

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(pos <= mid) update(l,st,mid,pos,val,N);
    else update(r,mid+1,ed,pos,val,N);

    tree[N][idx] = min(tree[N][l], tree[N][r]);
}

int query(int idx, int st, int ed ,int i, int j, int N)
{
    if(st == i && ed == j) return tree[N][idx];

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(j <= mid) return query(l,st,mid,i,j,N);
    else if(i > mid) return query(r,mid+1,ed,i,j,N);
    else return min(query(l,st,mid,i,mid,N), query(r,mid+1,ed,mid+1,j,N));
}

int main()
{
    //freopen("c:\\Users\\User\\Desktop\\in.txt", "r", stdin);

    int i, j, k, n, q, idx = 0, r, c;
    LL lo, hi, mid;
    char ch;

    scanf("%d %d", &n, &q);
    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &P[i].second, &P[i].first, &dir[i]);
        S.insert(P[i].first);
    }

    M[idx] = IM[idx] = idx;
    for(set<int>::iterator it = S.begin(); it != S.end(); it++)
        M[*it] = ++idx, IM[idx] = *it;

    M[n+1] = ++idx;
    IM[idx] = n+1;

    assert(idx <= 200010);

    update(1,0,idx,0,0,0);
    update(1,0,idx,idx,0,1);

    for(i = 1; i <= idx; i++)
    {
        update(1,0,idx,i,n+1-IM[i],0);
        update(1,0,idx,i,IM[i], 1);
    }

    for(i = 1; i <= q; i++)
    {
        r = P[i].first;
        c = P[i].second;
        ch = dir[i];

        if(ch == 'U')
        {
            lo = 0;
            hi = M[r]-1;
            while(lo != hi)
            {
                mid = lo + (hi-lo+1)/2;
                if(query(1,0,idx,mid,hi,0) <= c) lo = mid;
                else hi = mid-1;
            }

            if(!rpt[0][M[r]] && !rpt[1][M[r]])
            {
                printf("%d\n", r-IM[lo]);
                update(1,0,idx,M[r],IM[lo]+1,1);
                rpt[0][M[r]] = true;
            }
            else puts("0");
        }

        else
        {
            lo = M[r]+1;
            hi = idx;

            while(lo != hi)
            {
                mid = (lo+hi)/2;
                if(query(1,0,idx,lo,mid,1) <= r) hi = mid;
                else lo = mid+1;
            }

            if(!rpt[1][M[r]] && !rpt[0][M[r]])
            {
                printf("%d\n", c - (n+1-IM[lo]));
                update(1,0,idx,M[r], n +1-IM[lo]+1, 0);
                rpt[1][M[r]] = true;
            }
            else puts("0");
        }
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define inf     (1<<30)
#define MAX     300000
#define D(x)    printf("-> %d\n",x)

pair<int,int> P[MAX+10];
char dir[MAX+10];
set<int> S;
map<int,int> M, IM;

int tree[3][MAX+10];
bool rpt[3][MAX+10];
// 0 -> Column Segment
// 1 -> Row Segment

void update(int idx, int st, int ed, int pos, int val, int N)
{
    if(st == ed)
    {
        tree[N][idx] = val;
        return;
    }

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(pos <= mid) update(l,st,mid,pos,val,N);
    else update(r,mid+1,ed,pos,val,N);

    tree[N][idx] = min(tree[N][l], tree[N][r]);
}

int query(int idx, int st, int ed ,int i, int j, int N)
{
    assert(i >= 0 && j >= 0);
    if(st == i && ed == j) return tree[N][idx];

    int l = 2*idx, r = l|1, mid = (st+ed)/2;
    if(j <= mid) return query(l,st,mid,i,j,N);
    else if(i > mid) return query(r,mid+1,ed,i,j,N);
    else return min(query(l,st,mid,i,mid,N), query(r,mid+1,ed,mid+1,j,N));
}

int main()
{
    //freopen("c:\\Users\\User\\Desktop\\in.txt", "r", stdin);

    int i, j, k, n, q, idx = 0, r, c, lo, hi, mid;
    char ch;

    scanf("%d %d", &n, &q);
    for(i = 1; i <= q; i++)
    {
        scanf("%d %d %c", &P[i].second, &P[i].first, &dir[i]);
        S.insert(P[i].first);
    }

    M[idx] = IM[idx] = idx;
    for(set<int>::iterator it = S.begin(); it != S.end(); it++)
        M[*it] = ++idx, IM[idx] = *it;

    M[n+1] = ++idx;
    IM[idx] = n+1;

    update(1,0,idx,0,0,0);
    update(1,0,idx,idx,0,1);

    for(i = 1; i <= idx; i++)
    {
        update(1,0,idx,i,n+1-IM[i],0);
        update(1,0,idx,i,IM[i], 1);
    }

    for(i = 1; i <= q; i++)
    {
        r = P[i].first;
        c = P[i].second;
        ch = dir[i];

        if(ch == 'U')
        {
            lo = 0;
            hi = M[r]-1;
            while(lo != hi)
            {
                mid = lo + (hi-lo+1)/2;
                if(query(1,0,idx,mid,hi,0) <= c) lo = mid;
                else hi = mid-1;
            }

            if(!rpt[0][M[r]] && !rpt[1][M[r]])
            {
                printf("%d\n", r-IM[lo]-1 + !rpt[1][M[r]]);
                update(1,0,idx,M[r],IM[lo]+1,1);
                rpt[0][M[r]] = true;
            }
            else puts("0");
        }

        else
        {
            lo = M[r]+1;
            hi = idx;

            while(lo != hi)
            {
                mid = (lo+hi)/2;
                if(query(1,0,idx,lo,mid,1) <= r) hi = mid;
                else lo = mid+1;
            }

            if(!rpt[1][M[r]] && !rpt[0][M[r]])
            {
                printf("%d\n", c - (n+1-IM[lo]) -1 + !rpt[0][M[r]]);
                update(1,0,idx,M[r], n +1-IM[lo]+1, 0);
                rpt[1][M[r]] = true;
            }
            else puts("0");
        }
    }

    return 0;
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
	int li;
	int ri;
	Node *l;
	Node *r;

	int val;

	bool hupd;
	int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
	Node *n = new Node;
	n->li = li;
	n->ri = ri;
	n->upd = 0;
	if(li == ri){
		n->val = -1; //init
	}else{
		int mi = (li+ri)/2;
		n->r = build(li, mi);
		n->l = build(mi+1, ri);

		n->val = std::max(n->r->val, n->l->val); // merge
	}
	return n;
}

int query(Node *n, int li, int ri){
	if(ri < n->li || n->ri < li){
		//outside
		return -1;
	}else if(li <= n->li && n->ri <= ri){
		//inside
		return n->val;
	}

	int la = query(n->l, li, ri);
	int ra = query(n->r, li, ri);
	return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
	if(ri < n->li || n->ri < li){
		//outside
		return;
	}else if(li <= n->li && n->ri <= ri){
		n->val = v; //update
		return;
	}

	update(n->l, li, ri, v);
	update(n->r, li, ri, v);
	n->val = std::max(n->r->val, n->l->val); // merge
}

int main(){
	std::cin >> n >> q;
	r = build(0, 211111);
	r2 = build(0, 211111);

	std::set<int> tx;
	std::set<int> ty;
	for(int i=0; i<q; ++i){
		std::cin >> nx[i] >> ny[i] >> nc[i];
		tx.insert(nx[i]);
		ty.insert(ny[i]);
	}
	int c = 1;
	for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
		mpx[*iter] = c;
		mpxr[c] = *iter;
		++c;
	}
	int cxl = c;
	c = 1;
	for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
		mpy[*iter] = c;
		mpyr[c] = *iter;
		++c;
	}
	int cyl = c;
	for(int i=0; i<q; ++i){
		if(nc[i] == 'L'){
			int mn = 0;
			int mx = mpx[nx[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r, md, mpx[nx[i]]) >= cyl-mpy[ny[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << nx[i] << std::endl;
			}else{
				std::cout << std::max(0, nx[i]-mpxr[mn-1]) << std::endl;
			}
			update(r2, mpy[ny[i]], mpy[ny[i]], cyl-mn);

			//return 0;
		}else{
			int mn = 0;
			int mx = mpy[ny[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r2, md, mpy[ny[i]]) >= cxl-mpx[nx[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << ny[i] << std::endl;
			}else{
				std::cout << std::max(0, ny[i]-mpyr[mn-1]) << std::endl;
			}
			update(r, mpx[nx[i]], mpx[nx[i]], cxl-mn);
		}
	}
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
	int li;
	int ri;
	Node *l;
	Node *r;

	int val;

	bool hupd;
	int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
	Node *n = new Node;
	n->li = li;
	n->ri = ri;
	n->upd = 0;
	if(li == ri){
		n->val = -1; //init
	}else{
		int mi = (li+ri)/2;
		n->r = build(li, mi);
		n->l = build(mi+1, ri);

		n->val = std::max(n->r->val, n->l->val); // merge
	}
	return n;
}

int query(Node *n, int li, int ri){
	if(ri < n->li || n->ri < li){
		//outside
		return -1;
	}else if(li <= n->li && n->ri <= ri){
		//inside
		return n->val;
	}

	int la = query(n->l, li, ri);
	int ra = query(n->r, li, ri);
	return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
	if(ri < n->li || n->ri < li){
		//outside
		return;
	}else if(li <= n->li && n->ri <= ri){
		n->val = v; //update
		return;
	}

	update(n->l, li, ri, v);
	update(n->r, li, ri, v);
	n->val = std::max(n->r->val, n->l->val); // merge
}

int main(){
	std::cin >> n >> q;
	r = build(0, 211111);
	r2 = build(0, 211111);

	std::set<int> tx;
	std::set<int> ty;
	for(int i=0; i<q; ++i){
		std::cin >> nx[i] >> ny[i] >> nc[i];
		tx.insert(nx[i]);
		ty.insert(ny[i]);
	}
	int c = 1;
	for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
		mpx[*iter] = c;
		mpxr[c] = *iter;
		++c;
	}
	int cxl = c;
	c = 1;
	for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
		mpy[*iter] = c;
		mpyr[c] = *iter;
		++c;
	}
	int cyl = c;
	for(int i=0; i<q; ++i){
		if(nc[i] == 'L'){
			int mn = 0;
			int mx = mpx[nx[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r, md, mpx[nx[i]]) >= cyl-mpy[ny[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << nx[i] << std::endl;
			}else{
				std::cout << nx[i]-mpxr[mn-1] << std::endl;
			}
			update(r2, mpy[ny[i]], mpy[ny[i]], cyl-mn);

			//return 0;
		}else{
			int mn = 0;
			int mx = mpy[ny[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r2, md, mpy[ny[i]]) >= cxl-mpx[nx[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << ny[i] << std::endl;
			}else{
				std::cout << ny[i]-mpyr[mn-1] << std::endl;
			}
			update(r, mpx[nx[i]], mpx[nx[i]], cxl-mn);
		}
	}
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
    int li;
    int ri;
    Node *l;
    Node *r;

    int val;

    bool hupd;
    int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
    Node *n = new Node;
    n->li = li;
    n->ri = ri;
    n->upd = 0;
    if(li == ri){
        n->val = -1; //init
    }else{
        int mi = (li+ri)/2;
        n->l = build(li, mi);
        n->r = build(mi+1, ri);

        n->val = std::max(n->l->val, n->r->val); // merge
    }
    return n;
}

int query(Node *n, int li, int ri){
    if(ri < n->li || n->ri < li){
        //outside
        return -1;
    }else if(li <= n->li && n->ri <= ri){
        //inside
        return n->val;
    }

    int la = query(n->l, li, ri);
    int ra = query(n->r, li, ri);
    return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
    if(ri < n->li || n->ri < li){
        //outside
        return;
    }else if(li <= n->li && n->ri <= ri){
        n->val = v; //update
        return;
    }

    update(n->l, li, ri, v);
    update(n->r, li, ri, v);
    n->val = std::max(n->r->val, n->l->val); // merge
}

int bquery(Node *n, int li, int ri, int mi){
    if(ri < n->li || n->ri < li){
        //outside
        return INT_MAX;
    }else if(li <= n->li && n->ri <= ri){
        //inside
        if(n->li == n->ri){
            if(n->val < mi) return n->li;
            return INT_MAX;
        }else if(n->r->val < mi) return std::min(n->r->li, bquery(n->l, li, ri, mi));
        else return bquery(n->r, li, ri, mi);
    }

    int a = query(n->r, li, ri);
    if(a < mi) return std::min(n->r->li, bquery(n->l, li, ri, mi));
    else return bquery(n->r, li, ri, mi);
}

int main(){
    std::cin >> n >> q;
    r = build(0, 111111);
    r2 = build(0, 111111);

    std::set<int> tx;
    std::set<int> ty;
    std::set<std::pair<int, int >> hs;
    for(int i=0; i<q; ++i){
        std::cin >> nx[i] >> ny[i] >> nc[i];
        tx.insert(nx[i]);
        ty.insert(ny[i]);
    }
    int c = 1;
    for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
        mpx[*iter] = c;
        mpxr[c] = *iter;
        ++c;
    }
    int cxl = c;
    c = 1;
    for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
        mpy[*iter] = c;
        mpyr[c] = *iter;
        ++c;
    }
    int cyl = c;
    for(int i=0; i<q; ++i){
        if(hs.find(std::make_pair(nx[i], ny[i])) != hs.end()) {
            std::cout << 0 << std::endl;
            continue;
        }
        hs.insert(std::make_pair(nx[i], ny[i]));
        if(nc[i] == 'L'){
            int mn = bquery(r, 0, mpx[nx[i]], cyl-mpy[ny[i]]);
            if(mn == 0){
                std::cout << nx[i] << std::endl;
            }else{
                std::cout << nx[i]-mpxr[mn-1] << std::endl;
            }
            update(r2, mpy[ny[i]], mpy[ny[i]], cxl-mn);

            //return 0;
        }else{
            int mn = bquery(r2, 0, mpy[ny[i]], cxl-mpx[nx[i]]);
            if(mn == 0){
                std::cout << ny[i] << std::endl;
            }else{
                std::cout << ny[i]-mpyr[mn-1] << std::endl;
            }
            update(r, mpx[nx[i]], mpx[nx[i]], cyl-mn);
        }
    }
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
    int li;
    int ri;
    Node *l;
    Node *r;

    int val;

    bool hupd;
    int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
    Node *n = new Node;
    n->li = li;
    n->ri = ri;
    n->upd = 0;
    if(li == ri){
        n->val = -1; //init
    }else{
        int mi = (li+ri)/2;
        n->r = build(li, mi);
        n->l = build(mi+1, ri);

        n->val = std::max(n->r->val, n->l->val); // merge
    }
    return n;
}

int query(Node *n, int li, int ri){
    if(ri < n->li || n->ri < li){
        //outside
        return -1;
    }else if(li <= n->li && n->ri <= ri){
        //inside
        return n->val;
    }

    int la = query(n->l, li, ri);
    int ra = query(n->r, li, ri);
    return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
    if(ri < n->li || n->ri < li){
        //outside
        return;
    }else if(li <= n->li && n->ri <= ri){
        n->val = v; //update
        return;
    }

    update(n->l, li, ri, v);
    update(n->r, li, ri, v);
    n->val = std::max(n->r->val, n->l->val); // merge
}

int main(){
    std::cin >> n >> q;
    r = build(0, 211111);
    r2 = build(0, 211111);

    std::set<int> tx;
    std::set<int> ty;
    std::set<std::pair<int, int >> hs;
    for(int i=0; i<q; ++i){
        std::cin >> nx[i] >> ny[i] >> nc[i];
        tx.insert(nx[i]);
        ty.insert(ny[i]);
    }
    int c = 1;
    for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
        mpx[*iter] = c;
        mpxr[c] = *iter;
        ++c;
    }
    int cxl = c;
    c = 1;
    for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
        mpy[*iter] = c;
        mpyr[c] = *iter;
        ++c;
    }
    int cyl = c;
    for(int i=0; i<q; ++i){
        if(hs.find(std::make_pair(nx[i], ny[i])) != hs.end()) {
            std::cout << 0 << std::endl;
            continue;
        }
        hs.insert(std::make_pair(nx[i], ny[i]));
        if(nc[i] == 'L'){
            int mn = 0;
            int mx = mpx[nx[i]]+1;
            while(mn < mx){
                int md = (mn+mx)/2;
                if(query(r, md, mpx[nx[i]]) >= cyl-mpy[ny[i]]) mn = md+1;
                else mx = md;
            }
            if(mn == 0){
                std::cout << nx[i] << std::endl;
            }else{
                std::cout << nx[i]-mpxr[mn-1] << std::endl;
            }
            update(r2, mpy[ny[i]], mpy[ny[i]], cxl-mn);

            //return 0;
        }else{
            int mn = 0;
            int mx = mpy[ny[i]]+1;
            while(mn < mx){
                int md = (mn+mx)/2;
                if(query(r2, md, mpy[ny[i]]) >= cxl-mpx[nx[i]]) mn = md+1;
                else mx = md;
            }
            if(mn == 0){
                std::cout << ny[i] << std::endl;
            }else{
                std::cout << ny[i]-mpyr[mn-1] << std::endl;
            }
            update(r, mpx[nx[i]], mpx[nx[i]], cyl-mn);
        }
    }
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
	int li;
	int ri;
	Node *l;
	Node *r;

	int val;

	bool hupd;
	int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
	Node *n = new Node;
	n->li = li;
	n->ri = ri;
	n->upd = 0;
	if(li == ri){
		n->val = -1; //init
	}else{
		int mi = (li+ri)/2;
		n->r = build(li, mi);
		n->l = build(mi+1, ri);

		n->val = std::max(n->r->val, n->l->val); // merge
	}
	return n;
}

int query(Node *n, int li, int ri){
	if(ri < n->li || n->ri < li){
		//outside
		return -1;
	}else if(li <= n->li && n->ri <= ri){
		//inside
		return n->val;
	}

	int la = query(n->l, li, ri);
	int ra = query(n->r, li, ri);
	return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
	if(ri < n->li || n->ri < li){
		//outside
		return;
	}else if(li <= n->li && n->ri <= ri){
		n->val = v; //update
		return;
	}

	update(n->l, li, ri, v);
	update(n->r, li, ri, v);
	n->val = std::max(n->r->val, n->l->val); // merge
}

int main(){
	std::cin >> n >> q;
	r = build(0, 211111);
	r2 = build(0, 211111);

	std::set<int> tx;
	std::set<int> ty;
	for(int i=0; i<q; ++i){
		std::cin >> nx[i] >> ny[i] >> nc[i];
		tx.insert(nx[i]);
		ty.insert(ny[i]);
	}
	int c = 1;
	for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
		mpx[*iter] = c;
		mpxr[c] = *iter;
		++c;
	}
	int cxl = c;
	c = 1;
	for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
		mpy[*iter] = c;
		mpyr[c] = *iter;
		++c;
	}
	int cyl = c;
	for(int i=0; i<q; ++i){
		if(nc[i] == 'L'){
			int mn = 0;
			int mx = mpx[nx[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r, md, mpx[nx[i]]) >= cyl-mpy[ny[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << nx[i] << std::endl;
			}else{
				std::cout << std::max(0, nx[i]-mpxr[mn-1]) << std::endl;
			}
			update(r2, mpy[ny[i]], mpy[ny[i]], cxl-mn);

			//return 0;
		}else{
			int mn = 0;
			int mx = mpy[ny[i]]+1;
			while(mn < mx){
				int md = (mn+mx)/2;
				if(query(r2, md, mpy[ny[i]]) >= cxl-mpx[nx[i]]) mn = md+1;
				else mx = md;
			}
			if(mn == 0){
				std::cout << ny[i] << std::endl;
			}else{
				std::cout << std::max(0, ny[i]-mpyr[mn-1]) << std::endl;
			}
			update(r, mpx[nx[i]], mpx[nx[i]], cyl-mn);
		}
	}
}


#include <bits/stdc++.h>

int n, q;
std::map<int, int> mpx;
std::map<int, int> mpxr;
std::map<int, int> mpy;
std::map<int, int> mpyr;

int nx[211111];
int ny[211111];
char nc[211111];

// inclusion segment tree (a node includes both it endpoints!)
struct Node{
Node(): li(0), ri(0), l(0), r(0) {}
    int li;
    int ri;
    Node *l;
    Node *r;

    int val;

    bool hupd;
    int upd;
};

Node *r;
Node *r2;

Node *build(int li, int ri) {
    Node *n = new Node;
    n->li = li;
    n->ri = ri;
    n->upd = 0;
    if(li == ri){
        n->val = -1; //init
    }else{
        int mi = (li+ri)/2;
        n->r = build(li, mi);
        n->l = build(mi+1, ri);

        n->val = std::max(n->r->val, n->l->val); // merge
    }
    return n;
}

int query(Node *n, int li, int ri){
    if(ri < n->li || n->ri < li){
        //outside
        return -1;
    }else if(li <= n->li && n->ri <= ri){
        //inside
        return n->val;
    }

    int la = query(n->l, li, ri);
    int ra = query(n->r, li, ri);
    return std::max(la, ra); // merge
}

void update(Node *n, int li, int ri, int v){
    if(ri < n->li || n->ri < li){
        //outside
        return;
    }else if(li <= n->li && n->ri <= ri){
        n->val = v; //update
        return;
    }

    update(n->l, li, ri, v);
    update(n->r, li, ri, v);
    n->val = std::max(n->r->val, n->l->val); // merge
}

int main(){
    std::cin >> n >> q;
    r = build(0, 211111);
    r2 = build(0, 211111);

    std::set<int> tx;
    std::set<int> ty;
    for(int i=0; i<q; ++i){
        std::cin >> nx[i] >> ny[i] >> nc[i];
        tx.insert(nx[i]);
        ty.insert(ny[i]);
    }
    int c = 1;
    for(auto iter = tx.begin(); iter!=tx.end(); ++iter){
        mpx[*iter] = c;
        mpxr[c] = *iter;
        ++c;
    }
    int cxl = c+1;
    c = 1;
    for(auto iter = ty.begin(); iter!=ty.end(); ++iter){
        mpy[*iter] = c;
        mpyr[c] = *iter;
        ++c;
    }
    int cyl = c+1;
    for(int i=0; i<q; ++i){
        if(nc[i] == 'L'){
            int mn = 0;
            int mx = mpx[nx[i]]+1;
            while(mn < mx){
                int md = (mn+mx)/2;
                if(query(r, md, mpx[nx[i]]) >= cyl-mpy[ny[i]]) mn = md+1;
                else mx = md;
            }
            if(mn == 0){
                std::cout << nx[i] << std::endl;
            }else{
                std::cout << nx[i]-mpxr[mn-1] << std::endl;
            }
            update(r2, mpy[ny[i]], mpy[ny[i]], cyl-mn);

            //return 0;
        }else{
            int mn = 0;
            int mx = mpy[ny[i]]+1;
            while(mn < mx){
                int md = (mn+mx)/2;
                if(query(r2, md, mpy[ny[i]]) >= cxl-mpx[nx[i]]) mn = md+1;
                else mx = md;
            }
            if(mn == 0){
                std::cout << ny[i] << std::endl;
            }else{
                std::cout << ny[i]-mpyr[mn-1] << std::endl;
            }
            update(r, mpx[nx[i]], mpx[nx[i]], cxl-mn);
        }
    }
}