/*
Mohit Dhattarwal
*/
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define gcd(a,b) __gcd(a,b)

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define filewr() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,ll> psl;
typedef pair<ll,string> pls;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = 3.1415926535897932384626433832795;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

void solve()
{
	ll n,m,s,f;
	cin>>n>>m>>s>>f;
	string ans = "";
	string add = "R";
	if(s>f)
	{
		add = "L";
	}
	ll prev = 0;
	ll t,l,r;
	ll count = abs(s-f);
	for(ll i =0; i<m; i++)
	{
		cin>>t>>l>>r;
		if(t>prev+1 && count>0)
		{
			for(ll j=0; j<(t-prev-1) && count>0; j++)
			{
				ans+=add;
				count--;
			}
			prev = t-1;
		}
		if(t==prev+1 && count>0)
		{
			ll curr;
			if(f>s)
			{
				curr = s+(f-s)-count;
				if(curr<l-1 || curr>r)
				{
					ans+=add;
					count--;
				}
				else
				{
					ans+="X";
				}
			}
			else if(s>f)
			{
				curr = s - (s-f) + count;
				//tr(curr);
				if(curr<l || curr>r+1)
				{
					ans+=add;
					count--;
				}
				else
				{
					ans+="X";
				}
			}
			prev = t;
		}
	}
	for(ll i =0; i<count; i++)
	{
		ans+=add;
	}
	cout<<ans<<'\n';
}

int main(){
	fastio();
	ll t;
	t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}


/*
Mohit Dhattarwal
*/
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define gcd(a,b) __gcd(a,b)

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define filewr() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<string,ll> psl;
typedef pair<ll,string> pls;

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
int l=v.size();for(int i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const ld PI = 3.1415926535897932384626433832795;

typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

void solve()
{
	ll n,m,s,f;
	cin>>n>>m>>s>>f;
	string ans = "";
	string add = "R";
	if(s>f)
	{
		add = "L";
	}
	ll prev = 0;
	ll t,l,r;
	ll count = abs(s-f);
	for(ll i =0; i<m; i++)
	{
		cin>>t>>l>>r;
		if(t>prev+1 && count>0)
		{
			for(ll j=0; j<(t-prev-1) && count>0; j++)
			{
				ans+=add;
				count--;
			}
			prev = t-1;
		}
		if(t==prev+1 && count>0)
		{
			ll curr;
			if(f>s)
			{
				curr = s+(f-s)-count;
				if(curr<l-1 || curr>r)
				{
					ans+=add;
					count--;
				}
				else
				{
					ans+="X";
				}
			}
			else if(s>f)
			{
				curr = s - (s-f) + count;
				//tr(curr);
				if(curr<l || curr>r+1)
				{
					ans+=add;
					count--;
				}
				else
				{
					ans+="X";
				}
			}
			prev = t;
		}
	}
	cout<<ans<<'\n';
}

int main(){
	fastio();
	ll t;
	t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}


// Motto:-Fail early,Fail Often,Fail Forward.
//	while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }
	#include<bits/stdc++.h>
	using namespace std;
	//=============================LOL======================
	#define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vnn         vector<vector<int>>
    #define vii         vector<pii>
    #define vs          vector<string>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define endl        '\n'
	#define sz(x)       (int)(x).size()
	#define thunder     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
	//=============================LOL========================
	//++++++++++++++++++++++++Optimisations+++++++++++++++
	//#pragma GCC optimize("O1")
	//#pragma GCC optimize("O2")
	//#pragma GCC optimize("O3")
	//#pragma GCC optimize("Os")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC target("avx,avx2,fma")
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//=========================Chal,Nikal.ab==========================
	#define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
    #define MOD         1000000007
    #define hell        998244353
    #define output(x) cout << (x ? "YES" : "NO")<<endl;
	#define Output(x) cout << (x ? "Yes" : "No")<<endl;
	//=========================Chal,Nikal.ab=============================
	//---------------------------Hushiyari mat dikha---------------------------------
	#define MOD2 (998244353)
    #define MOD3 (1000000009)
    #define PI acos(-1)
    #define eps (1e-8)
	#define INF (1e18)
	template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
	template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
	template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
	template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
	ifstream cinn("in.txt");ofstream coutt("out.txt");
	int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
	//---------------------------Hushiyari mat dikha--------------------------------------
	/*ll gcd(ll a, ll b)
    {
    if (b == 0)
        return a;
    return gcd(b, a % b);
    }*/
    signed main()
    {
        thunder;
        int t,n,l,r,s,c,h,k,f1,f2,t1,t2,i,j,ans,f,mn;
        cin>>n>>k>>s>>f;
        c=s;
        fo(i,0,k)
        {
            cin>>t>>l>>r;
            if(i+1==t)
            {
                if(c>=l && c<=r || (c+1<n && (c+1>=l && c+1<=r))){
                    cout<<'X';
                }
                else if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
            }
            else
            {
                 if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
            }

        }
        cout<<endl;

    }


// Motto:-Fail early,Fail Often,Fail Forward.
//	while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }
	#include<bits/stdc++.h>
	using namespace std;
	//=============================LOL======================
	#define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vnn         vector<vector<int>>
    #define vii         vector<pii>
    #define vs          vector<string>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define endl        '\n'
	#define sz(x)       (int)(x).size()
	#define thunder     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
	//=============================LOL========================
	//++++++++++++++++++++++++Optimisations+++++++++++++++
	//#pragma GCC optimize("O1")
	//#pragma GCC optimize("O2")
	//#pragma GCC optimize("O3")
	//#pragma GCC optimize("Os")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC target("avx,avx2,fma")
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//=========================Chal,Nikal.ab==========================
	#define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
    #define MOD         1000000007
    #define hell        998244353
    #define output(x) cout << (x ? "YES" : "NO")<<endl;
	#define Output(x) cout << (x ? "Yes" : "No")<<endl;
	//=========================Chal,Nikal.ab=============================
	//---------------------------Hushiyari mat dikha---------------------------------
	#define MOD2 (998244353)
    #define MOD3 (1000000009)
    #define PI acos(-1)
    #define eps (1e-8)
	#define INF (1e18)
	template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
	template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
	template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
	template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
	ifstream cinn("in.txt");ofstream coutt("out.txt");
	int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
	//---------------------------Hushiyari mat dikha--------------------------------------
	/*ll gcd(ll a, ll b)
    {
    if (b == 0)
        return a;
    return gcd(b, a % b);
    }*/
    signed main()
    {
        thunder;
        int t,n,l,r,s,c,h,k,f1,f2,t1,t2,i,j,ans,f,mn;
        cin>>n>>k>>s>>f;
        c=s;
        fo(i,0,k)
        {
            cin>>t>>l>>r;
            if(i+1==t)
            {
                if(c>=l && c<=r || (c+1<n && (c+1>=l && c+1<=r) && c<f) || (c-1>=0 && (c-1>=l && c-1<=r)) && c>f){
                    cout<<'X';
                }
                else if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
            }
            else
            {
                 if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
            }

        }
        cout<<endl;

    }


// Motto:-Fail early,Fail Often,Fail Forward.
//	while(true)
// {
//     if(AC)
//     {
//         break;
//     }
//     else if(Contest Over)
//     {
//         Try.
//         Check out Editorial.
//         Understand.
//         Find out your Mistake.
//         Learn the topic (if new).
//         Solve Problems on that topic (if new).
//         Upsolve that problem.
//         break;
//     }
//     else
//     {
//         Try.
//         Use Pen-Paper.
//         Find errors, edge cases, etc.
//         continue;
//     }
// }
	#include<bits/stdc++.h>
	using namespace std;
	//=============================LOL======================
	#define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vnn         vector<vector<int>>
    #define vii         vector<pii>
    #define vs          vector<string>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define endl        '\n'
	#define sz(x)       (int)(x).size()
	#define thunder     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
	//=============================LOL========================
	//++++++++++++++++++++++++Optimisations+++++++++++++++
	//#pragma GCC optimize("O1")
	//#pragma GCC optimize("O2")
	//#pragma GCC optimize("O3")
	//#pragma GCC optimize("Os")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC optimize("Ofast")
	//#pragma GCC target("avx,avx2,fma")
	//++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//=========================Chal,Nikal.ab==========================
	#define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
    #define MOD         1000000007
    #define hell        998244353
    #define output(x) cout << (x ? "YES" : "NO")<<endl;
	#define Output(x) cout << (x ? "Yes" : "No")<<endl;
	//=========================Chal,Nikal.ab=============================
	//---------------------------Hushiyari mat dikha---------------------------------
	#define MOD2 (998244353)
    #define MOD3 (1000000009)
    #define PI acos(-1)
    #define eps (1e-8)
	#define INF (1e18)
	template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
	template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
	template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
	template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
	ifstream cinn("in.txt");ofstream coutt("out.txt");
	int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
	//---------------------------Hushiyari mat dikha--------------------------------------
	/*ll gcd(ll a, ll b)
    {
    if (b == 0)
        return a;
    return gcd(b, a % b);
    }*/
    signed main()
    {
        thunder;
        int t,n,l,r,s,c,h,k,f1,f2,t1,t2,i,j,ans,f,mn,ind=0;
        cin>>n>>k>>s>>f;
        map<int,int> m;
        pii p[k];
        c=s;
        fo(i,0,k)
        {
            cin>>t>>l>>r;
            m[t]=1;
            p[i].x=l;
            p[i].y=r;
        }
        h=0,ind=0;
        while(1)
        {
            h++;
            if(c==f) break;
            if(m[h]==1)
            {
                if(c>=p[ind].x && c<=p[ind].y || (c+1<n && (c+1>=p[ind].x && c+1<=p[ind].y) && c<f) || (c-1>=1 && (c-1>=p[ind].x && c-1<=p[ind].y)) && c>f){
                    cout<<'X';
                }
                else if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
                ind++;
            }
            else
            {
                 if(c<f)
                {
                    cout<<'R';
                    c++;
                }
                else if(c>f)
                {
                    cout<<'L';
                    c--;
                }
            }

        }
        cout<<endl;

    }


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,a,b) for(ll i=a;i<b;i++)
inline const char nl = '\n';
inline const ll MOD = 1000000007;
inline const ld pi = 3.141592653589793238;

int fscn() {
    fio;
    int c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    int sg = 0;
    if (c == '-') {
        c = getchar();
        sg = 1;
    }
    int ret = 0;
    while (c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return sg ? -ret : ret;
}
bool a[50][50];
bool b[50][50];
ll calc(ll x, ll y, ll na, ll ma, ll nb, ll mb){
    ll sum = 0;
    For(i,0,na){
        For(j,0,ma){
            if(i+x>=0&&i+x<nb&&j+y>=0&&j+y<mb){
                sum+=(a[i][j]*b[i+x][j+y]);
            }
        }
    }
    return sum;
}
void solve(){
    fio;
    ll n = fscn(), m = fscn(), s = fscn(), f = fscn();
    ll t,l,r,pastT=0;
    For(i,0,m){
        t = fscn(), l = fscn(), r = fscn();
        while(pastT+1<t){
            if(s==f) break;
            else if(s<f) {s+=1; cout<<"R";}
            else if(s>f) {s-=1; cout<<"L";}
            pastT++;
        }
        pastT = t;
        if(s==f) continue;
        else if(s>f&&(s<l||s-1>r)){s-=1; cout<<"L";}
        else if(s<f&&(s+1<l||s>r)){s+=1; cout<<"R";}
        else{cout<<"X";}
    }
    while(s!=f){
        if(s<f){s+=1; cout<<"R";}
        else if(s>f){s-=1; cout<<"L";}
    }
    cout<<nl;
}

int main(){
    #ifdef APAN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fio;
    solve();
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,a,b) for(ll i=a;i<b;i++)
inline const char nl = '\n';
inline const ll MOD = 1000000007;
inline const ld pi = 3.141592653589793238;

int fscn() {
    fio;
    int c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    int sg = 0;
    if (c == '-') {
        c = getchar();
        sg = 1;
    }
    int ret = 0;
    while (c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return sg ? -ret : ret;
}
bool a[50][50];
bool b[50][50];
ll calc(ll x, ll y, ll na, ll ma, ll nb, ll mb){
    ll sum = 0;
    For(i,0,na){
        For(j,0,ma){
            if(i+x>=0&&i+x<nb&&j+y>=0&&j+y<mb){
                sum+=(a[i][j]*b[i+x][j+y]);
            }
        }
    }
    return sum;
}
void solve(){
    fio;
    ll n = fscn(), m = fscn(), s = fscn(), f = fscn();
    ll t,l,r;
    For(i,0,m){
        t = fscn(), l = fscn(), r = fscn();
        if(s==f) continue;
        else if(s>f&&(s-1>r||s-1<l)){s-=1; cout<<"L";}
        else if(s<f&&(s+1>r||s+1<l)){s+=1; cout<<"R";}
        else{cout<<"X";}
    }
    cout<<nl;
}

int main(){
    #ifdef APAN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fio;
    solve();
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,a,b) for(ll i=a;i<b;i++)
inline const char nl = '\n';
inline const ll MOD = 1000000007;
inline const ld pi = 3.141592653589793238;

int fscn() {
    fio;
    int c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    int sg = 0;
    if (c == '-') {
        c = getchar();
        sg = 1;
    }
    int ret = 0;
    while (c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return sg ? -ret : ret;
}
bool a[50][50];
bool b[50][50];
ll calc(ll x, ll y, ll na, ll ma, ll nb, ll mb){
    ll sum = 0;
    For(i,0,na){
        For(j,0,ma){
            if(i+x>=0&&i+x<nb&&j+y>=0&&j+y<mb){
                sum+=(a[i][j]*b[i+x][j+y]);
            }
        }
    }
    return sum;
}
void solve(){
    fio;
    ll n = fscn(), m = fscn(), s = fscn(), f = fscn();
    ll t,l,r,pastT=0;
    For(i,0,m){
        t = fscn(), l = fscn(), r = fscn();
        while(pastT+1<t){
            if(s==f) continue;
            else if(s<f) {s+=1; cout<<"R";}
            else if(s>f) {s-=1; cout<<"L";}
            pastT++;
        }
        pastT = t;
        if(s==f) continue;
        else if(s>f&&(s<l||s-1>r)){s-=1; cout<<"L";}
        else if(s<f&&(s+1<l||s>r)){s+=1; cout<<"R";}
        else{cout<<"X";}
    }
    while(s!=f){
        if(s<f){s+=1; cout<<"R";}
        else {s-=1; cout<<"L";}
    }
    cout<<nl;
}

int main(){
    #ifdef APAN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fio;
    solve();
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,a,b) for(ll i=a;i<b;i++)
inline const char nl = '\n';
inline const ll MOD = 1000000007;
inline const ld pi = 3.141592653589793238;

int fscn() {
    fio;
    int c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    int sg = 0;
    if (c == '-') {
        c = getchar();
        sg = 1;
    }
    int ret = 0;
    while (c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return sg ? -ret : ret;
}
bool a[50][50];
bool b[50][50];
ll calc(ll x, ll y, ll na, ll ma, ll nb, ll mb){
    ll sum = 0;
    For(i,0,na){
        For(j,0,ma){
            if(i+x>=0&&i+x<nb&&j+y>=0&&j+y<mb){
                sum+=(a[i][j]*b[i+x][j+y]);
            }
        }
    }
    return sum;
}
void solve(){
    fio;
    ll n = fscn(), m = fscn(), s = fscn(), f = fscn();
    ll t,l,r,pastT=1;
    For(i,0,m){
        t = fscn(), l = fscn(), r = fscn();
        while(pastT+1<t){
            if(s==f) break;
            else if(s<f) {s+=1; cout<<"R";}
            else if(s>f) {s-=1; cout<<"L";}
            pastT++;
        }
        if(s==f) continue;
        else if(s>f&&(s-1>r||s-1<l)){s-=1; cout<<"L";}
        else if(s<f&&(s+1>r||s+1<l)){s+=1; cout<<"R";}
        else{cout<<"X";}
        pastT = t;
    }
    cout<<nl;
}

int main(){
    #ifdef APAN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fio;
    solve();
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define For(i,a,b) for(ll i=a;i<b;i++)
inline const char nl = '\n';
inline const ll MOD = 1000000007;
inline const ld pi = 3.141592653589793238;

int fscn() {
    fio;
    int c = getchar();
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    int sg = 0;
    if (c == '-') {
        c = getchar();
        sg = 1;
    }
    int ret = 0;
    while (c >= '0' && c <= '9') {
        ret = ret * 10 + c - '0';
        c = getchar();
    }
    return sg ? -ret : ret;
}
bool a[50][50];
bool b[50][50];
ll calc(ll x, ll y, ll na, ll ma, ll nb, ll mb){
    ll sum = 0;
    For(i,0,na){
        For(j,0,ma){
            if(i+x>=0&&i+x<nb&&j+y>=0&&j+y<mb){
                sum+=(a[i][j]*b[i+x][j+y]);
            }
        }
    }
    return sum;
}
void solve(){
    fio;
    ll n = fscn(), m = fscn(), s = fscn(), f = fscn();
    ll t,l,r,pastT=0;
    For(i,0,m){
        t = fscn(), l = fscn(), r = fscn();
        while(pastT+1<t){
            if(s==f) break;
            else if(s<f) {s+=1; cout<<"R";}
            else if(s>f) {s-=1; cout<<"L";}
            pastT++;
        }
        if(s==f) continue;
        else if(s>f&&(s-1>r||s-1<l)&&(s<l||s>r)){s-=1; cout<<"L";}
        else if(s<f&&(s+1>r||s+1<l)&&(s<l||s>r)){s+=1; cout<<"R";}
        else{cout<<"X";}
        pastT = t;
    }
    cout<<nl;
}

int main(){
    #ifdef APAN
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    fio;
    solve();
    return 0;
}


///GOD is Allmighty.
///Hore Krisna,Lord Krisna.

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;*/
using ll=long long;
using ld=long double;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read freopen ("in.txt","r",stdin);
#define out freopen ("out.txt","w",stdout);
#define reset(a,b) memset(a, (b), sizeof(a))
#define fr1(p,i,k,z) for (ll i=p ; i<=k ; i+=z)
#define rf1(p,i,k,z) for (ll i=p ; i>=k ; i-=z)
#define fr0(p,i,k,z) for (ll i=p ; i<k ; i+=z)
#define rf0(p,i,k,z) for (ll i=p-1 ; i>=k ; i-=z)
#define dcfr1(p,i,k,f,e,z) for (ll i=p ; i<=k&&f>e ; i+=z)
#define dcrf1(p,i,k,f,e,z) for (ll i=p ; i>=k&&f>e ; i-=z)
#define dcfr0(p,i,k,f,e,z) for (ll i=p ; i<k&&f>e ; i+=z)
#define dcrf0(p,i,k,f,e,z) for (ll i=p-1 ; i>=k&&f>e ; i-=z)
#define min3(a,b,c) min(a, min(b,c))
#define min4(a,b,c,d) min(a, min(b,min(c,d)))
#define max3(a,b,c) max(a, max(b,c))
#define max4(a,b,c,d) max(a, max(b,max(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a/gcd(a,b))*b)
#define pfg(a) cout <<(a)<<" "
#define pf(a) cout <<(a)
#define pfl(a) cout<<(a)<<endl
#define pf2(a,b) cout <<(a)<<" "<<(b)<<endl
#define pf3(a,b,c) cout <<(a)<<" "<<(b)<<" "<<(c)<<endl
#define pf4(a,b,c,d) cout <<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define pfp(x,y)      cout<<fixed<<setprecision(y)<<x
#define pyes  cout<<"YES"<<endl
#define pno   cout<<"NO"<<endl
#define in(a) cin >>(a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define in5(a,b,c,d,e) cin >> (a) >> (b) >> (c) >> (d) >>(e)
#define in6(a,b,c,d,e,f) cin >> (a) >> (b) >> (c) >> (d) >>(e) >>(f)
#define gline(z,s) getline(cin,s)
#define sz(x) int((x).size())
#define sortv(k)     sort(k.begin(),k.end())
#define rev(k)       reverse(k.begin(),k.end())
#define all(k)       k.begin(), k.end()
#define umin(a,b)    a=min(a,b)
#define umax(a,b)    a=max(a,b)
///macros
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
///constants
constexpr ll lmax = 1e18;
constexpr ll imax = 1e9;
constexpr ll imin =-1e9;
constexpr ll mod = 1e9+7;
constexpr ld eps = 1e-9;
///Direction array
//int dx[]={-1,0,1,0,-1,1,-1,1};//adjcell move
//int dy[]={0,-1,0,1,-1,-1,1,1};//adjcell move
//int dx[]={-2,-1,1,2,2,1,-1,-2};///knight move
//int dy[]={1,2,2,1,-1,-2,-2,-1};///knight move
///stl arrays
//vector<string>s;
//unordered_map<ll,ll>ump;
//map<ll,ll>Mp;
//set<ll>sl;
//set<pair<ll,ll>>sp;
//vector<pair<ll,ll>>vp;
///2D stl arrays
//vector<ll>adj[20005];
//vector<pii/pll>adj[20005];
///heap
//priority_queue<int>pmax;
//priority_queue<int,vector<int>,greater<int>>pmin;
///arrays
//ll a[1000005];
//ll a[200005];
//ll b[1000005];
//ll idx[1000005];
//ll dp[10005][10005];
//ll pos[1000005],neg[1000005];
//string a[100005];
//char indx[100005];
//bool vis[20005]={false};
//ll steps=1;
//cin.get(); skip newline at string
///*************************Keep Coding***********************************

/*set<char> vow = {'a','e','i','o','u'};
bool isvow(char c)
{
     return vow.find(c) != vow.end();
}*/
/*int num(char ch)
{
    int n=ch-'0';
    return n;
}
/*
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}*/
/*bool compair(pair<int,pair<int,int>>a,pair<int,pair<int,int>>b)
{
    if(a.first<b.first) return true;
    else if(a.first==b.first&&a.second.first<b.second.first) return true;
    else if(a.first==b.first&&a.second.first==b.second.first&&a.second.second<b.second.second) return true;
    return false;
}*/
/*bool compair(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.ff==b.ff)return a.ss<b.ss;
    return a.ff>b.ff;
}*/
/*bool compair(string a,string b)
{
    return a.size()<b.size();
}*/
/*bool sign(ll num)
{
    return num>0;
}*/
ll multimod(ll A, ll B) {
    A *= B;
    A %= mod;
    return A;
}
ll addmod(ll A, ll B) {
    ll C = (A + B) % mod;
    return C;
}
int n,m,s,f,l,r,t,tt=0;
//string s,p;
void solve()
{
    in4(n,m,s,f);
    string ans="";
    if(s<f)
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='R';
                    s++;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s+1<l || s+1 >r)&& (s!=f)) ans+='R',s++;
                else if(s!=f) ans+='X';
            }
            else
            {
                if((s<l || s>r ) && (s+1<l || s+1 >r)) ans+='R',s++;
                else ans+='X';
            }
        }
    }
    else
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='L';
                    s--;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s-1<l || s-1>r) && (s!=f)) ans+='L',s--;
                else if(s!=f) ans+='X';
                pfl(s);
            }
            else
            {
                if((s<l || s>r ) && (s-1<l || s-1>r)) ans+='L',s--;
                else ans+='X';
            }
        }

    }
    pf(ans);
    return;
    ///********************MAKE ALL THE INT LL****************************
}
int main()
{
    fast;
    //read;//out;
    int tc=1;
    //in(tc);
    while(tc--) solve();
    return 0;
}


///GOD is Allmighty.
///Hore Krisna,Lord Krisna.

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;*/
using ll=long long;
using ld=long double;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read freopen ("in.txt","r",stdin);
#define out freopen ("out.txt","w",stdout);
#define reset(a,b) memset(a, (b), sizeof(a))
#define fr1(p,i,k,z) for (ll i=p ; i<=k ; i+=z)
#define rf1(p,i,k,z) for (ll i=p ; i>=k ; i-=z)
#define fr0(p,i,k,z) for (ll i=p ; i<k ; i+=z)
#define rf0(p,i,k,z) for (ll i=p-1 ; i>=k ; i-=z)
#define dcfr1(p,i,k,f,e,z) for (ll i=p ; i<=k&&f>e ; i+=z)
#define dcrf1(p,i,k,f,e,z) for (ll i=p ; i>=k&&f>e ; i-=z)
#define dcfr0(p,i,k,f,e,z) for (ll i=p ; i<k&&f>e ; i+=z)
#define dcrf0(p,i,k,f,e,z) for (ll i=p-1 ; i>=k&&f>e ; i-=z)
#define min3(a,b,c) min(a, min(b,c))
#define min4(a,b,c,d) min(a, min(b,min(c,d)))
#define max3(a,b,c) max(a, max(b,c))
#define max4(a,b,c,d) max(a, max(b,max(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a/gcd(a,b))*b)
#define pfg(a) cout <<(a)<<" "
#define pf(a) cout <<(a)
#define pfl(a) cout<<(a)<<endl
#define pf2(a,b) cout <<(a)<<" "<<(b)<<endl
#define pf3(a,b,c) cout <<(a)<<" "<<(b)<<" "<<(c)<<endl
#define pf4(a,b,c,d) cout <<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define pfp(x,y)      cout<<fixed<<setprecision(y)<<x
#define pyes  cout<<"YES"<<endl
#define pno   cout<<"NO"<<endl
#define in(a) cin >>(a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define in5(a,b,c,d,e) cin >> (a) >> (b) >> (c) >> (d) >>(e)
#define in6(a,b,c,d,e,f) cin >> (a) >> (b) >> (c) >> (d) >>(e) >>(f)
#define gline(z,s) getline(cin,s)
#define sz(x) int((x).size())
#define sortv(k)     sort(k.begin(),k.end())
#define rev(k)       reverse(k.begin(),k.end())
#define all(k)       k.begin(), k.end()
#define umin(a,b)    a=min(a,b)
#define umax(a,b)    a=max(a,b)
///macros
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
///constants
constexpr ll lmax = 1e18;
constexpr ll imax = 1e9;
constexpr ll imin =-1e9;
constexpr ll mod = 1e9+7;
constexpr ld eps = 1e-9;
///Direction array
//int dx[]={-1,0,1,0,-1,1,-1,1};//adjcell move
//int dy[]={0,-1,0,1,-1,-1,1,1};//adjcell move
//int dx[]={-2,-1,1,2,2,1,-1,-2};///knight move
//int dy[]={1,2,2,1,-1,-2,-2,-1};///knight move
///stl arrays
//vector<string>s;
//unordered_map<ll,ll>ump;
//map<ll,ll>Mp;
//set<ll>sl;
//set<pair<ll,ll>>sp;
//vector<pair<ll,ll>>vp;
///2D stl arrays
//vector<ll>adj[20005];
//vector<pii/pll>adj[20005];
///heap
//priority_queue<int>pmax;
//priority_queue<int,vector<int>,greater<int>>pmin;
///arrays
//ll a[1000005];
//ll a[200005];
//ll b[1000005];
//ll idx[1000005];
//ll dp[10005][10005];
//ll pos[1000005],neg[1000005];
//string a[100005];
//char indx[100005];
//bool vis[20005]={false};
//ll steps=1;
//cin.get(); skip newline at string
///*************************Keep Coding***********************************

/*set<char> vow = {'a','e','i','o','u'};
bool isvow(char c)
{
     return vow.find(c) != vow.end();
}*/
/*int num(char ch)
{
    int n=ch-'0';
    return n;
}
/*
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}*/
/*bool compair(pair<int,pair<int,int>>a,pair<int,pair<int,int>>b)
{
    if(a.first<b.first) return true;
    else if(a.first==b.first&&a.second.first<b.second.first) return true;
    else if(a.first==b.first&&a.second.first==b.second.first&&a.second.second<b.second.second) return true;
    return false;
}*/
/*bool compair(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.ff==b.ff)return a.ss<b.ss;
    return a.ff>b.ff;
}*/
/*bool compair(string a,string b)
{
    return a.size()<b.size();
}*/
/*bool sign(ll num)
{
    return num>0;
}*/
ll multimod(ll A, ll B) {
    A *= B;
    A %= mod;
    return A;
}
ll addmod(ll A, ll B) {
    ll C = (A + B) % mod;
    return C;
}
int n,m,s,f,l,r,t,tt=0;
//string s,p;
void solve()
{
    in4(n,m,s,f);
    string ans="";
    if(s<f)
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='R';
                    s++;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s+1<l || s+1 >r)&& (s!=f)) ans+='R',s++;
                else if(s!=f) ans+='X';
            }
            else
            {
                if((s<l || s>r ) && (s+1<l || s+1 >r)) ans+='R',s++;
                else ans+='X';
            }
        }
    }
    else
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='L';
                    s--;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s-1<l || s-1>r) && (s!=f)) ans+='L',s--;
                else if(s!=f) ans+='X';
            }
            else
            {
                if((s<l || s>r ) && (s-1<l || s-1>r)) ans+='L',s--;
                else ans+='X';
            }
        }

    }
    pf(ans);
    return;
    ///********************MAKE ALL THE INT LL****************************
}
int main()
{
    fast;
    //read;//out;
    int tc=1;
    //in(tc);
    while(tc--) solve();
    return 0;
}


///GOD is Allmighty.
///Hore Krisna,Lord Krisna.

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;*/
using ll=long long;
using ld=long double;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read freopen ("in.txt","r",stdin);
#define out freopen ("out.txt","w",stdout);
#define reset(a,b) memset(a, (b), sizeof(a))
#define fr1(p,i,k,z) for (ll i=p ; i<=k ; i+=z)
#define rf1(p,i,k,z) for (ll i=p ; i>=k ; i-=z)
#define fr0(p,i,k,z) for (ll i=p ; i<k ; i+=z)
#define rf0(p,i,k,z) for (ll i=p-1 ; i>=k ; i-=z)
#define dcfr1(p,i,k,f,e,z) for (ll i=p ; i<=k&&f>e ; i+=z)
#define dcrf1(p,i,k,f,e,z) for (ll i=p ; i>=k&&f>e ; i-=z)
#define dcfr0(p,i,k,f,e,z) for (ll i=p ; i<k&&f>e ; i+=z)
#define dcrf0(p,i,k,f,e,z) for (ll i=p-1 ; i>=k&&f>e ; i-=z)
#define min3(a,b,c) min(a, min(b,c))
#define min4(a,b,c,d) min(a, min(b,min(c,d)))
#define max3(a,b,c) max(a, max(b,c))
#define max4(a,b,c,d) max(a, max(b,max(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a/gcd(a,b))*b)
#define pfg(a) cout <<(a)<<" "
#define pf(a) cout <<(a)
#define pfl(a) cout<<(a)<<endl
#define pf2(a,b) cout <<(a)<<" "<<(b)<<endl
#define pf3(a,b,c) cout <<(a)<<" "<<(b)<<" "<<(c)<<endl
#define pf4(a,b,c,d) cout <<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define pfp(x,y)      cout<<fixed<<setprecision(y)<<x
#define pyes  cout<<"YES"<<endl
#define pno   cout<<"NO"<<endl
#define in(a) cin >>(a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define in5(a,b,c,d,e) cin >> (a) >> (b) >> (c) >> (d) >>(e)
#define in6(a,b,c,d,e,f) cin >> (a) >> (b) >> (c) >> (d) >>(e) >>(f)
#define gline(z,s) getline(cin,s)
#define sz(x) int((x).size())
#define sortv(k)     sort(k.begin(),k.end())
#define rev(k)       reverse(k.begin(),k.end())
#define all(k)       k.begin(), k.end()
#define umin(a,b)    a=min(a,b)
#define umax(a,b)    a=max(a,b)
///macros
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
///constants
constexpr ll lmax = 1e18;
constexpr ll imax = 1e9;
constexpr ll imin =-1e9;
constexpr ll mod = 1e9+7;
constexpr ld eps = 1e-9;
///Direction array
//int dx[]={-1,0,1,0,-1,1,-1,1};//adjcell move
//int dy[]={0,-1,0,1,-1,-1,1,1};//adjcell move
//int dx[]={-2,-1,1,2,2,1,-1,-2};///knight move
//int dy[]={1,2,2,1,-1,-2,-2,-1};///knight move
///stl arrays
//vector<string>s;
//unordered_map<ll,ll>ump;
//map<ll,ll>Mp;
//set<ll>sl;
//set<pair<ll,ll>>sp;
//vector<pair<ll,ll>>vp;
///2D stl arrays
//vector<ll>adj[20005];
//vector<pii/pll>adj[20005];
///heap
//priority_queue<int>pmax;
//priority_queue<int,vector<int>,greater<int>>pmin;
///arrays
//ll a[1000005];
//ll a[200005];
//ll b[1000005];
//ll idx[1000005];
//ll dp[10005][10005];
//ll pos[1000005],neg[1000005];
//string a[100005];
//char indx[100005];
//bool vis[20005]={false};
//ll steps=1;
//cin.get(); skip newline at string
///*************************Keep Coding***********************************

/*set<char> vow = {'a','e','i','o','u'};
bool isvow(char c)
{
     return vow.find(c) != vow.end();
}*/
/*int num(char ch)
{
    int n=ch-'0';
    return n;
}
/*
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}*/
/*bool compair(pair<int,pair<int,int>>a,pair<int,pair<int,int>>b)
{
    if(a.first<b.first) return true;
    else if(a.first==b.first&&a.second.first<b.second.first) return true;
    else if(a.first==b.first&&a.second.first==b.second.first&&a.second.second<b.second.second) return true;
    return false;
}*/
/*bool compair(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.ff==b.ff)return a.ss<b.ss;
    return a.ff>b.ff;
}*/
/*bool compair(string a,string b)
{
    return a.size()<b.size();
}*/
/*bool sign(ll num)
{
    return num>0;
}*/
ll multimod(ll A, ll B) {
    A *= B;
    A %= mod;
    return A;
}
ll addmod(ll A, ll B) {
    ll C = (A + B) % mod;
    return C;
}
int n,m,s,f,l,r,t,tt=1;
//string s,p;
void solve()
{
    in4(n,m,s,f);
    string ans="";
    if(s<f)
    {
        while(m--)
        {
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=abs(t-tt);
                while(dif--)
                {
                    ans+='R';
                    s++;
                    if(s==f) break;
                }
            }
            else
            {
                if((s<l || s>r ) && (s+1<l || s+1 >r)) ans+='R',s++;
                else ans+='X';
            }
            tt++;
        }
    }
    else
    {
        while(m--)
        {
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=abs(t-tt);
                while(dif--)
                {
                    ans+='L';
                    s--;
                    if(s==f) break;
                }
            }
            else
            {
                if((s<l || s>r ) && (s-1<l || s-1 >r)) ans+='L',s--;
                else ans+='X';
            }
            tt++;
        }

    }
    pf(ans);
    return;
    ///********************MAKE ALL THE INT LL****************************
}
int main()
{
    fast;
    //read;//out;
    int tc=1;
    //in(tc);
    while(tc--) solve();
    return 0;
}


///GOD is Allmighty.
///Hore Krisna,Lord Krisna.

#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*using namespace __gnu_pbds;
template<typename T>
using ordered_set=tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;*/
using ll=long long;
using ld=long double;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read freopen ("in.txt","r",stdin);
#define out freopen ("out.txt","w",stdout);
#define reset(a,b) memset(a, (b), sizeof(a))
#define fr1(p,i,k,z) for (ll i=p ; i<=k ; i+=z)
#define rf1(p,i,k,z) for (ll i=p ; i>=k ; i-=z)
#define fr0(p,i,k,z) for (ll i=p ; i<k ; i+=z)
#define rf0(p,i,k,z) for (ll i=p-1 ; i>=k ; i-=z)
#define dcfr1(p,i,k,f,e,z) for (ll i=p ; i<=k&&f>e ; i+=z)
#define dcrf1(p,i,k,f,e,z) for (ll i=p ; i>=k&&f>e ; i-=z)
#define dcfr0(p,i,k,f,e,z) for (ll i=p ; i<k&&f>e ; i+=z)
#define dcrf0(p,i,k,f,e,z) for (ll i=p-1 ; i>=k&&f>e ; i-=z)
#define min3(a,b,c) min(a, min(b,c))
#define min4(a,b,c,d) min(a, min(b,min(c,d)))
#define max3(a,b,c) max(a, max(b,c))
#define max4(a,b,c,d) max(a, max(b,max(c,d)))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) ((a/gcd(a,b))*b)
#define pfg(a) cout <<(a)<<" "
#define pf(a) cout <<(a)
#define pfl(a) cout<<(a)<<endl
#define pf2(a,b) cout <<(a)<<" "<<(b)<<endl
#define pf3(a,b,c) cout <<(a)<<" "<<(b)<<" "<<(c)<<endl
#define pf4(a,b,c,d) cout <<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define pfp(x,y)      cout<<fixed<<setprecision(y)<<x
#define pyes  cout<<"YES"<<endl
#define pno   cout<<"NO"<<endl
#define in(a) cin >>(a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define in5(a,b,c,d,e) cin >> (a) >> (b) >> (c) >> (d) >>(e)
#define in6(a,b,c,d,e,f) cin >> (a) >> (b) >> (c) >> (d) >>(e) >>(f)
#define gline(z,s) getline(cin,s)
#define sz(x) int((x).size())
#define sortv(k)     sort(k.begin(),k.end())
#define rev(k)       reverse(k.begin(),k.end())
#define all(k)       k.begin(), k.end()
#define umin(a,b)    a=min(a,b)
#define umax(a,b)    a=max(a,b)
///macros
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define pi acos(-1.0)
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
///constants
constexpr ll lmax = 1e18;
constexpr ll imax = 1e9;
constexpr ll imin =-1e9;
constexpr ll mod = 1e9+7;
constexpr ld eps = 1e-9;
///Direction array
//int dx[]={-1,0,1,0,-1,1,-1,1};//adjcell move
//int dy[]={0,-1,0,1,-1,-1,1,1};//adjcell move
//int dx[]={-2,-1,1,2,2,1,-1,-2};///knight move
//int dy[]={1,2,2,1,-1,-2,-2,-1};///knight move
///stl arrays
//vector<string>s;
//unordered_map<ll,ll>ump;
//map<ll,ll>Mp;
//set<ll>sl;
//set<pair<ll,ll>>sp;
//vector<pair<ll,ll>>vp;
///2D stl arrays
//vector<ll>adj[20005];
//vector<pii/pll>adj[20005];
///heap
//priority_queue<int>pmax;
//priority_queue<int,vector<int>,greater<int>>pmin;
///arrays
//ll a[1000005];
//ll a[200005];
//ll b[1000005];
//ll idx[1000005];
//ll dp[10005][10005];
//ll pos[1000005],neg[1000005];
//string a[100005];
//char indx[100005];
//bool vis[20005]={false};
//ll steps=1;
//cin.get(); skip newline at string
///*************************Keep Coding***********************************

/*set<char> vow = {'a','e','i','o','u'};
bool isvow(char c)
{
     return vow.find(c) != vow.end();
}*/
/*int num(char ch)
{
    int n=ch-'0';
    return n;
}
/*
ll fact(ll n)
{
    if (n <= 1)
        return 1;
    return n * fact(n - 1);
}
ll nPr(ll n, ll r)
{
    return fact(n) / fact(n - r);
}
ll nCr(ll n, ll r)
{
    return fact(n) / (fact(r) * fact(n - r));
}*/
/*bool compair(pair<int,pair<int,int>>a,pair<int,pair<int,int>>b)
{
    if(a.first<b.first) return true;
    else if(a.first==b.first&&a.second.first<b.second.first) return true;
    else if(a.first==b.first&&a.second.first==b.second.first&&a.second.second<b.second.second) return true;
    return false;
}*/
/*bool compair(pair<ll,ll>a,pair<ll,ll>b)
{
    if(a.ff==b.ff)return a.ss<b.ss;
    return a.ff>b.ff;
}*/
/*bool compair(string a,string b)
{
    return a.size()<b.size();
}*/
/*bool sign(ll num)
{
    return num>0;
}*/
ll multimod(ll A, ll B) {
    A *= B;
    A %= mod;
    return A;
}
ll addmod(ll A, ll B) {
    ll C = (A + B) % mod;
    return C;
}
int n,m,s,f,l,r,t,tt=0;
//string s,p;
void solve()
{
    in4(n,m,s,f);
    string ans="";
    if(s<f)
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='R';
                    s++;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s+1<l || s+1 >r)&& (s!=f)) ans+='R',s++;
                else if(s!=f) ans+='X';
            }
            else
            {
                if((s<l || s>r ) && (s+1<l || s+1 >r)) ans+='R',s++;
                else ans+='X';
            }
        }
        if(s!=f)
        {
            while(s<f)
            {
                ans+='R';
                s++;
            }
        }
    }
    else
    {
        while(m--)
        {
            tt++;
            in3(t,l,r);
            if(s==f) continue;
            if(t!=tt)
            {
                int dif=t-tt;
                tt=t;
                while(dif--)
                {
                    ans+='L';
                    s--;
                    if(s==f) break;
                }
                if((s<l || s>r ) && (s-1<l || s-1>r) && (s!=f)) ans+='L',s--;
                else if(s!=f) ans+='X';
            }
            else
            {
                if((s<l || s>r ) && (s-1<l || s-1>r)) ans+='L',s--;
                else ans+='X';
            }
        }
        if(s!=f)
        {
            while(s>f)
            {
                ans+='L';
                s--;
            }
        }

    }
    pf(ans);
    return;
    ///********************MAKE ALL THE INT LL****************************
}
int main()
{
    fast;
    //read;//out;
    int tc=1;
    //in(tc);
    while(tc--) solve();
    return 0;
}


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

#define loopy cout<<"loopy"<<" "
#define pp pair<int,int>
#define pb push_back
#define sp " "
#define nl "\n"
#define pf cout<<
#define fir first
#define sec second

typedef long long int ll;
using namespace std;
/*
bool iseven(int n)
{
    if(n%2==0)
        return true;
    else
        return false;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

*/

int main()
{
    ll n,m, s,f;
    cin>>n>>m>>s>>f;
    ll a,b,c;
    vector<vector<int>> vec;

    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        vec.pb({a,b,c});
    }
    string todo;
    ll curr=s;
    if(s<f)
    {
        a=1;
        todo="R";
    }
    else
    {
        a=-1;
        todo="L";
    }
    int i=0;
    ll step=0;
    while(curr!=f && i<m)
    {
        step++;
        if(step== vec[i][0])
        {
            if((curr>=vec[i][1] && curr<=vec[i][2]) || ((curr+a)>=vec[i][1] && (curr+a)<= vec[i][2]))
            {
                cout<<"X";
            }
            else
            {
                cout<<todo;
                curr+=a;
            }
            i++;
        }
        else
        {
        curr+=a;
        cout<<todo;
        }

    }
    for(int i=curr;i!=f;i=i+a)
    {
        cout<<todo;
    }

}


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

#define loopy cout<<"loopy"<<" "
#define pp pair<int,int>
#define pb push_back
#define sp " "
#define nl "\n"
#define pf cout<<
#define fir first
#define sec second

typedef long long int ll;
using namespace std;
/*
bool iseven(int n)
{
    if(n%2==0)
        return true;
    else
        return false;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

*/

int main()
{
    ll n,m, s,f;
    cin>>n>>m>>s>>f;
    ll a,b,c;
    vector<vector<int>> vec;

    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        vec.pb({a,b,c});
    }
    string todo;
    ll curr=s;
    if(s<f)
    {
        a=1;
        todo="R";
    }
    else
    {
        a=-1;
        todo="L";
    }
    int i=0;
    ll step=0;
    while(curr!=f && i<m)
    {

        if(step== vec[i][0])
        {   step++;
            if((curr>=vec[i][1] && curr<=vec[i][2]) || ((curr+a)>=vec[i][1] && (curr+a)<= vec[i][2]))
            {
                cout<<"X";
            }
            else
            {
                cout<<todo;
                curr+=a;
            }
            i++;
        }
        else
        {
        curr+=a;
        cout<<todo;
        }

    }
    for(int i=curr;i!=f;i=i+a)
    {
        cout<<todo;
    }

}


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

#define loopy cout<<"loopy"<<" "
#define pp pair<int,int>
#define pb push_back
#define sp " "
#define nl "\n"
#define pf cout<<
#define fir first
#define sec second

typedef long long int ll;
using namespace std;
/*
bool iseven(int n)
{
    if(n%2==0)
        return true;
    else
        return false;
}
int gcd(int a, int b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

*/

int main()
{
    ll n,m, s,f;
    cin>>n>>m>>s>>f;
    ll a,b,c;
    vector<vector<int>> vec;

    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        vec.pb({a,b,c});
    }
    string todo;
    ll curr=s;
    if(s<f)
    {
        a=1;
        todo="R";
    }
    else
    {
        a=-1;
        todo="L";
    }
    int i=0;
    ll step=0;
    while(curr!=f && i<m)
    {
        step++;
        if(step== vec[i][0])
        {
            if((curr>=vec[i][1] && curr<=vec[i][2]) || ((curr+a)>=vec[i][1] && (curr+a)<= vec[i][2]))
            {
                cout<<"X";
            }
            else
            {
                cout<<todo;
                curr+=a;
            }
            i++;
        }
        else
        {
        curr+=a;
        cout<<todo;
        }
    }
    for(int i=curr;i!=f;i++)
    {
        cout<<todo;
    }

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<string.h>
#include<array>
#include<list>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<cstring>
#include<utility>
#include<set>
#include<cstdio>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pf push_front
#define in insert
#define all(v) v.begin(),v.end()
#define infinity (1 << 30)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long           ll;
typedef double              lf;
typedef unsigned long long  ull;

using namespace std;
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie();
    int n,m,i,s,f,x,l,r;
    cin>>n>>m>>s>>f;
    for(i=0; i<m; i++)
    {
        cin>>x>>l>>r;
        if(s==f)
        {
           // cout<<'X';
            continue;
        }
        if(s>f)
        {
            if(s-1<l||s-1>r)
            {
                cout<<'L';
                s--;
                continue;
            }
            else
            {
                cout<<'X';
                continue;
            }
        }
        if(s<f)
        {
            if(s+1<l||s+1>r)
            {
                cout<<'R';
                s++;
                continue;
            }
            else
            {
                cout<<'X';
                continue;
            }
        }
    }
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<string.h>
#include<array>
#include<list>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<cstring>
#include<utility>
#include<set>
#include<cstdio>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pf push_front
#define in insert
#define all(v) v.begin(),v.end()
#define infinity (1 << 30)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long           ll;
typedef double              lf;
typedef unsigned long long  ull;

using namespace std;
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie();
    int n,m,i,s,f,x,l,r,y=0;
    cin>>n>>m>>s>>f;
    for(i=0; i<m; i++)
    {
        cin>>x>>l>>r;
        //cout<<x<<" "<<y<<endl;
        while(y<x-1)
        {
            if(s==f)
                y++;
            if(s<f)
            {
                cout<<"R";
                s++;
                y++;
            }
            if(s>f)
            {
                cout<<"L";
                s--;
                y++;
            }
        }
        if(s==f)
            y++;
        if(s<f)
        {
            if(s+1<l||s+1>r)
            {
                cout<<"R";
                y++;
                s++;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }
        if(s>f)
        {
            if(s-1<l||s-1>r)
            {
                cout<<"L";
                y++;
                s--;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }

    }
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<string.h>
#include<array>
#include<list>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<cstring>
#include<utility>
#include<set>
#include<cstdio>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pf push_front
#define in insert
#define all(v) v.begin(),v.end()
#define infinity (1 << 30)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long           ll;
typedef double              lf;
typedef unsigned long long  ull;

using namespace std;
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie();
    int n,m,i,s,f,x,l,r,y=0;
    cin>>n>>m>>s>>f;
    for(i=0; i<m; i++)
    {
        cin>>x>>l>>r;
        //cout<<x<<" "<<y<<endl;
        while(y<x-1)
        {
            if(s==f)
                y++;
            if(s<f)
            {
                cout<<"R";
                s++;
                y++;
            }
            if(s>f)
            {
                cout<<"L";
                s--;
                y++;
            }
        }
        if(s==f)
            y++;
        if(s<f)
        {
            if((s+1<l||s+1>r) && (s<l||s>r))
            {
                cout<<"R";
                y++;
                s++;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }
        if(s>f)
        {
            if((s-1<l||s-1>r) && (s<l||s>r))
            {
                cout<<"L";
                y++;
                s--;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }

    }
    while(s!=f)
    {
        if(s<f)
        {
            cout<<"R";
            s++;

        }
        if(s>f)
        {
            cout<<"L";
            s--;

        }
    }
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#include<string.h>
#include<array>
#include<list>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<cstring>
#include<utility>
#include<set>
#include<cstdio>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pf push_front
#define in insert
#define all(v) v.begin(),v.end()
#define infinity (1 << 30)
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef long long           ll;
typedef double              lf;
typedef unsigned long long  ull;

using namespace std;
/*freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie();
    int n,m,i,s,f,x,l,r,y=0;
    cin>>n>>m>>s>>f;
    for(i=0; i<m; i++)
    {
        cin>>x>>l>>r;
        //cout<<x<<" "<<y<<endl;
        while(y<x-1)
        {
            if(s==f)
                y++;
            if(s<f)
            {
                cout<<"R";
                s++;
                y++;
            }
            if(s>f)
            {
                cout<<"L";
                s--;
                y++;
            }
        }
        if(s==f)
            y++;
        if(s<f)
        {
            if((s+1<l||s+1>r) && (s<l||s>r))
            {
                cout<<"R";
                y++;
                s++;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }
        if(s>f)
        {
            if((s-1<l||s-1>r) && (s<l||s>r))
            {
                cout<<"L";
                y++;
                s--;
            }
            else
            {
                cout<<"X";
                y++;
            }
        }

    }
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;i++)
#define f first
#define s second
#define sz size
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,s,f,k;cin>>n>>m>>s>>f;
int a[m][3];string v;vector<int>v1;
rep(i,0,m)
{cin>>a[i][0]>>a[i][1]>>a[i][2];
v1.pb(a[i][0]);}
sort(all(v1));
rep(i,1,v1[n-1]+1)
{
    int c=0;
    rep(j,0,m)
    {
        if(a[j][0]==i){c++;k=j;break;}
    }
    if(c==1)
    {
      if(f>s)
      {
        if((s>=a[k][1]&&s<=a[k][2])||(s+1>=a[k][1]&&s+1<=a[k][2]))
        cout<<"X";//v.pb('X');
        else
            {
               s=s+1;
               cout<<"R";//v.pb('R');
               //if(s==f)break;
           }
      }
      else if(s>f)
      {
          if((s>=a[k][1]&&s<=a[k][2])||(s-1>=a[k][1]&&s-1<=a[k][2]))
       cout<<"X";// v.pb('X');
        else
            {
               s=s-1;
               cout<<"L";//v.pb('L');
               //if(s==f)break;
           }
      }
      else break;
    }
    else
    {
       if(f>s){s=s+1;cout<<"R";/*v.pb('R');*/}
       else if(s>f){s=s-1;cout<<"L";/*v.pb('L');*/}
       else break;
    }
}
}


#include <bits/stdc++.h>
#define int long long
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
signed main(){
int n,m,s,f;
cin>>n>>m>>s>>f;
std::vector<pair<int,pair<int,int>>> v;
v.pb(mp(0,mp(0,0)));
rep(i,1,m+1){
  int a,b,c;
  cin>>a>>b>>c;
  v.pb(mp(a,mp(b,c)));
}
sort(all(v));
if(f>s){
  rep(i,0,m+1){
    if(v[i+1].fr-v[i].fr==1 && i!=m){
      if(i){
    if((s+1>=v[i].sc.fr && s+1<=v[i].sc.sc) || (s>=v[i].sc.fr && s<=v[i].sc.sc) ) cout<<"X";
    else {s++;cout<<"R";}
    if(s==f) break;
  }

  }
  else {
    if((s+1>=v[i].sc.fr && s+1<=v[i].sc.sc) || (s>=v[i].sc.fr && s<=v[i].sc.sc) ) cout<<"X";
    int x = (v[i+1].fr-v[i].fr)-1;
    while(x--)
    {
      cout<<"R";s++;if(s==f) break;
    }
    if(s==f) break;
  }
}
  if(s!=f) {rep(i,0,f-s)cout<<"R";}
}
else{
  rep(i,0,m+1){
    if(v[i+1].fr-v[i].fr==1 &&i!=m){
    if(i){
    if((s-1>=v[i].sc.fr && s-1<=v[i].sc.sc) || (s>=v[i].sc.fr && s<=v[i].sc.sc)) cout<<"X";

    else {s--;cout<<"L";}
    if(s==f) break;
  }

  }
  else{
      if((s-1>=v[i].sc.fr && s-1<=v[i].sc.sc) || (s>=v[i].sc.fr && s<=v[i].sc.sc)) cout<<"X";
    int x =(v[i+1].fr-v[i].fr)-1;
    while(x--)
    {
      cout<<"L";s--;if(s==f) break;
    }
    if(s==f) break;
  }
}
  if(s!=f) {rep(i,0,s-f)cout<<"L";}
}
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;i++)
#define f first
#define s second
#define sz size
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,s,f,k;
cin>>n>>m>>s>>f;
int t[m],l[m],r[m];
string v;
rep(i,0,m)
{
    cin>>t[i]>>l[i]>>r[i];
     if(t[i]==i+1)
     {
         if(f>s)
         {
             if((s>=l[i]&&s<=r[i])||((s+1)>=l[i]&&(s+1)<=r[i]))
                v.pb('X');
             else
             {
                 v.pb('R');
                 s+=1;
             }
         }
         else if(f<s)
         {
             if((s>=l[i]&&s<=r[i])||((s-1)>=l[i]&&(s-1)<=r[i]))
                v.pb('X');
             else
             {
                 v.pb('L');
                 s-=1;
             }
         }
         else break;
     }
     else
     {
         rep(j,i+1,t[i])
         {
             if(f>s){v.pb('R');s+=1;}
             else if(s>f){v.pb('L');s-=1;}
             else break;
         }
     }
}cout<<v;
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;i++)
#define f first
#define s second
#define sz size
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,s,f,k;cin>>n>>m>>s>>f;
int a[m][3];vector<char>v;
rep(i,0,m)
{cin>>a[i][0]>>a[i][1]>>a[i][2];
v.pb(a[i][0]);}
sort(all(v));
rep(i,1,v[n-1]+1)
{
    int c=0;
    rep(j,0,m)
    {
        if(a[j][0]==i){c++;k=j;break;}
    }
    if(c==1)
    {
      if(f>s)
      {
        if((s>=a[k][1]&&s<=a[k][2])||(s+1>=a[k][1]&&s+1<=a[k][2]))
        v.pb('X');
        else
            {
               s+=1;
               v.pb('R');
               if(s==f)break;
           }
      }
      else if(s>f)
      {
          if(s>=a[k][1]&&s<=a[k][2]&&s-1>=a[k][1]&&s-1<=a[k][2])
        v.pb('X');
        else
            {
               s-=1;
               v.pb('L');
               if(s==f)break;
           }
      }
      else break;
    }
    else
    {
       if(f>s){s+=1;v.pb('R');}
       else if(s>f){s-=1;v.pb('L');}
       else break;
    }
}
rep(i,0,v.sz()+1)cout<<v[i];
}


#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,n) for(int i=a;i<n;i++)
#define f first
#define s second
#define sz size
#define all(a) a.begin(),a.end()
#define int long long
using namespace std;
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n,m,s,f,k;
cin>>n>>m>>s>>f;
int t[m],l[m],r[m];
string v;
rep(i,0,m) cin>>t[i]>>l[i]>>r[i];
rep(i,0,m)
{

     if(t[i]==i+1||t[i]-t[i-1]==1)
     {
         if(f>s)
         {
             if((s>=l[i]&&s<=r[i])||((s+1)>=l[i]&&(s+1)<=r[i]))
                v.pb('X');
             else
             {
                 v.pb('R');
                 s+=1;
             }
         }
         else if(f<s)
         {
             if((s>=l[i]&&s<=r[i])||((s-1)>=l[i]&&(s-1)<=r[i]))
                v.pb('X');
             else
             {
                 v.pb('L');
                 s-=1;
             }
         }
         else break;
     }
     else
     {
         rep(j,i+1,t[i])
         {
             if(f>s){v.pb('R');s+=1;}
             else if(s>f){v.pb('L');s-=1;}
             else break;
         }
     }
}cout<<v;
}


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

#define pii pair<int, int>

typedef class Dsu {
  public:
    int *uf, *sz;
    boolean durable;
    stack<pii> opt;

    void init(int n) {
      durable = false;
      uf = new int[(n + 1)];
      sz = new int[(n + 1)];
      for (int i = 0; i <= n; i++)
        uf[i] = i, sz[i] = 1;
    }

    int find(int x) {
      return uf[x] == x ? x : find(uf[x]);
    }
    boolean unit(int x, int y) {
      x = find(x), y = find(y);
      if (sz[x] > sz[y])
        swap(x, y);
      if (x ^ y) {
        if (durable) {
          opt.push(pii(x, uf[x]));
        }
        uf[x] = y;
        sz[y] += sz[x];
        return true;
      }
      return false;
    }

    void revoke() {
      int x = opt.top().first, fx = opt.top().second;
      int y = find(x);
      sz[y] -= sz[x];
      uf[x] = fx;
      opt.pop();
    }
    boolean have_last() {
      return !opt.empty();
    }
    int operator [] (int x) {
      return find(x);
    }
} Dsu;

const int N = 1005;

int n, m, q;
char G[N][N];
vector<pii> mov;

int S, T;
Dsu uf;

boolean in_range(int x, int y) {
  return x >= 0 && x <= n + 1 && y >= 0 && y <= m + 1;
}
int id(int x, int y) {
  assert(in_range(x, y));
  return x * (m + 2) + y;
}

int main() {
//  freopen("a.in", "r", stdin);
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (dx || dy) {
        mov.emplace_back(dx, dy);
      }
    }
  }
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", G[i] + 1);
  }
  G[0][0] = G[1][0] = G[0][1] = '.';
  G[n + 1][m + 1] = G[n][m + 1] = G[n + 1][m] = '.';
  for (int i = 2; i <= m + 1; i++) {
    G[0][i] = '#';
    G[n + 1][i - 2] = '#';
  }
  for (int i = 2; i <= n + 1; i++) {
    G[i][0] = '#';
    G[i - 2][m + 1] = '#';
  }
  uf.init((n + 2) * (m + 2));
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (G[i][j] != '#')
        continue;
      for (auto d : mov) {
        int x = i + d.first, y = j + d.second;
        if (in_range(x, y) && G[x][y] == '#') {
          uf.unit(id(i, j), id(x, y));
        }
      }
    }
  }
  S = uf[id(0, 2)], T = uf[id(2, 0)];
  uf.durable = true;
  while (q--) {
    int num;
    vector<pii> P;
    scanf("%d", &num);
    for (int i = 0, x, y; i < num; i++) {
      scanf("%d%d", &x, &y);
      G[x][y] = '#';
      P.emplace_back(x, y);
    }
    for (auto p : P) {
      int x = p.first, y = p.second;
      for (auto d : mov) {
        int nx = x + d.first, ny = y + d.second;
        if (G[nx][ny] == '#') {
          uf.unit(id(x, y), id(nx, ny));
        }
      }
    }
    if (uf[S] == uf[T]) {
      puts("NO");
      goto query_end;
    }
    for (auto p : P) {
      int px = p.first, py = p.second;
      for (auto d : mov) {
        int x = px + d.first, y = py + d.second;
        if (x < 1 || x > n || y < 1 || y > m)
          continue;
        if (x == 1 && y == 1)
          continue;
        if (x == n && y == m)
          continue;
        if (G[x][y] == '.') {
          int cnt = 0;
          for (auto d2 : mov) {
            int nx = x + d2.first, ny = y + d2.second;
            if (in_range(nx, ny) && G[nx][ny] == '#') {
              cnt += uf.unit(id(x, y), id(nx, ny));
            }
          }
          if (uf[S] == uf[T]) {
            puts("NO");
            goto query_end;
          }
          while (cnt--)
            uf.revoke();
        }
      }
    }
    puts("YES");
query_end:
    for (auto p : P)
      G[p.first][p.second] = '.';
    while (uf.have_last())
      uf.revoke();
    fflush(stdout);
  }
  return 0;
}


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

#define pii pair<int, int>

typedef class Dsu {
  public:
    int *uf, *sz;
    boolean durable;
    stack<pii> opt;

    void init(int n) {
      durable = false;
      uf = new int[(n + 1)];
      sz = new int[(n + 1)];
      for (int i = 0; i <= n; i++)
        uf[i] = i, sz[i] = 1;
    }

    int _find(int x) {
      return uf[x] == x ? x : find(uf[x]);
    }
    int _find2(int x) {
      while (x ^ uf[x])
        x = uf[x];
      return x;
    }
    int find(int x) {
      return durable ? _find2(x) : _find(x);
    }
    boolean unit(int x, int y) {
      x = find(x), y = find(y);
      if (sz[x] > sz[y])
        swap(x, y);
      if (x ^ y) {
        if (durable) {
          opt.push(pii(x, uf[x]));
        }
        uf[x] = y;
        sz[y] += sz[x];
        return true;
      }
      return false;
    }

    void revoke() {
      int x = opt.top().first, fx = opt.top().second;
      int y = find(x);
      sz[y] -= sz[x];
      uf[x] = fx;
      opt.pop();
    }
    boolean have_last() {
      return !opt.empty();
    }
    int operator [] (int x) {
      return find(x);
    }
} Dsu;

const int N = 1005;

int n, m, q;
char G[N][N];
vector<pii> mov;
set<int> nearby[N * N];

int S, T;
Dsu uf;

boolean in_range(int x, int y) {
  return x >= 0 && x <= n + 1 && y >= 0 && y <= m + 1;
}
int id(int x, int y) {
  //  assert(in_range(x, y));
  return x * (m + 2) + y;
}
boolean can_block(int x, int y) {
  if (!in_range(x, y))
    return false;
  if (x < 1 || x > n || y < 1 || y > m)
    return false;
  if (x == 1 && y == 1)
    return false;
  if (x == n && y == m)
    return false;
  return true;
}

int add_around(int x, int y) {
  int p = id(x, y), rt = 0;
  for (auto d : mov) {
    int nx = d.first + x, ny = d.second + y;
    if (in_range(nx, ny) && G[nx][ny] == '#')
      rt += uf.unit(p, id(nx, ny));
  }
  return rt;
}

int main() {
  //  freopen("a.in", "r", stdin);
  for (int dx = -1; dx <= 1; dx++) {
    for (int dy = -1; dy <= 1; dy++) {
      if (dx || dy) {
        mov.emplace_back(dx, dy);
      }
    }
  }
  scanf("%d%d%d", &n, &m, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%s", G[i] + 1);
  }
  G[0][0] = G[1][0] = G[0][1] = '.';
  G[n + 1][m + 1] = G[n][m + 1] = G[n + 1][m] = '.';
  for (int i = 2; i <= m + 1; i++) {
    G[0][i] = '#';
    G[n + 1][i - 2] = '#';
  }
  for (int i = 2; i <= n + 1; i++) {
    G[i][0] = '#';
    G[i - 2][m + 1] = '#';
  }
  uf.init((n + 2) * (m + 2));
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (G[i][j] != '#')
        continue;
      add_around(i, j);
    }
  }
  for (int i = 0; i <= n + 1; i++) {
    for (int j = 0; j <= m + 1; j++) {
      if (G[i][j] == '#') {
        for (auto d : mov) {
          int x = i + d.first, y = j + d.second;
          if (!can_block(x, y) || G[x][y] != '.')
            continue;
          for (auto d2 : mov) {
            int nx = x + d2.first, ny = y + d2.second;
            if (in_range(nx, ny) && uf[id(nx, ny)] ^ uf[id(i, j)]) {
              nearby[uf[id(i, j)]].insert(uf[id(nx, ny)]);
            }
          }
        }
      }
    }
  }
  S = uf[id(0, 2)], T = uf[id(2, 0)];
  uf.durable = true;
  while (q--) {
    int num;
    vector<pii> P;
    scanf("%d", &num);
    for (int i = 0, x, y; i < num; i++) {
      scanf("%d%d", &x, &y);
      G[x][y] = '#';
      P.emplace_back(x, y);
    }
    vector<int> block;
    vector<int> bs {uf[S]}, bt {uf[T]};
    for (auto p : P) {
      int x = p.first, y = p.second;
      for (auto d : mov) {
        int nx = d.first + x, ny = d.second + y;
        if (in_range(nx, ny) && G[nx][ny] == '#') {
          block.push_back(uf[id(nx, ny)]);
          uf.unit(id(x, y), id(nx, ny));
        }
      }
    }
    if (uf[S] == uf[T]) {
      puts("NO");
      goto query_end;
    }
    for (auto p : P) {
      int px = p.first, py = p.second;
      for (auto d : mov) {
        int x = px + d.first, y = py + d.second;
        if (!can_block(x, y) || G[x][y] != '.')
          continue;
        boolean ns = false, nt = false;
        for (auto d2 : mov) {
          int nx = x + d2.first, ny = y + d2.second;
          if (!ns && uf[id(nx, ny)] == uf[S])
            ns = true;
          if (!nt && uf[id(nx, ny)] == uf[T])
            nt = true;
        }
        if (ns && nt) {
          puts("NO");
          goto query_end;
        }
      }
    }
    sort(block.begin(), block.end());
    block.erase(unique(block.begin(), block.end()), block.end());
    for (auto bid : block) {
      int fx = uf[bid];
      if (fx == uf[S]) {
        bs.push_back(bid);
      } else if (fx == uf[T]) {
        bt.push_back(bid);
      }
    }
    for (auto x : bs) {
      for (auto y : bt) {
        if (nearby[x].count(y)) {
          puts("NO");
          goto query_end;
        }
      }
    }
    puts("YES");
query_end:
    for (auto p : P)
      G[p.first][p.second] = '.';
    while (uf.have_last())
      uf.revoke();
    fflush(stdout);
  }
  return 0;
}
//hellobig_tq//hello


#include<bits/stdc++.h>
#define N 1005
#define M 1000005
using namespace std;

int m,n,cas,cnt,tp,sta,gol,id[N][N],fa[M],fa0[M],bx[N],by[N],q[N],rt[N];
char a[N][N]; bool vis[M];
int dx[8]={-1,-1,-1,0,1,1,1,0},dy[8]={-1,0,1,1,1,0,-1,-1};
struct hsh_node{
	int tot,fst[2010527],px[M<<3],py[M<<3],nxt[M<<3];
	void ins(int x,int y){
		if (!x || !y) return;
		if (x>y) swap(x,y);
		int z=(x*233+y)%2010527,i;
		for (i=fst[z]; i; i=nxt[i]) if (px[i]==x && py[i]==y) return;
		px[++tot]=x; py[tot]=y; nxt[tot]=fst[z]; fst[z]=tot;
	}
	bool check(int x,int y){
		if (x>y) swap(x,y);
		int z=(x*233+y)%2010527,i;
		for (i=fst[z]; i; i=nxt[i]) if (px[i]==x && py[i]==y) return 1;
		return 0;
	}
}hsh;
int getfa(int x){ if (!x){puts("no!");while(1);}return (x==fa[x])?x:fa[x]=getfa(fa[x]); }
int findfa(int x){ return (x==fa[x])?x:getfa(fa[x]); }
bool ok(){
	int i,j,S=findfa(sta),T=findfa(gol);
	if (S==T) return 0;
	for (i=1; i<=tp; i++) rt[i]=findfa(q[i]);
	for (i=1; i<=tp; i++) if (rt[i]==S)
		for (j=1; j<=tp; j++) if (rt[j]==T && hsh.check(q[i],q[j])) return 0;
	return 1;
}
int main(){
	scanf("%d%d%d",&m,&n,&cas);
	int i,j,k,l,x,y;
	for (i=1; i<=m; i++) scanf("%s",a[i]+1);
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) id[i][j]=(i-1)*n+j;
	sta=m*n+1; gol=sta+1;
	for (i=1; i<=gol; i++) fa[i]=i;
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) if (a[i][j]=='#'){
			x=id[i][j];
			for (k=0; k<8; k++)
				if (a[i+dx[k]][j+dy[k]]=='#')
					fa[getfa(x)]=getfa(id[i+dx[k]][j+dy[k]]);
			if (i==m || j==1) fa[getfa(x)]=getfa(sta);
			if (i==1 || j==n) fa[getfa(x)]=getfa(gol);
		}
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++){
			if (i+1==m || j==2) hsh.ins(getfa(sta),getfa(id[i][j]));
			if (i==2 || j+1==n) hsh.ins(getfa(gol),getfa(id[i][j]));
			for (k=0; k<8; k++)
				for (l=0; l<k; l++)
					if (abs(dx[k]-dx[l])==2 && abs(dy[k]-dy[l])==2 && (x=id[i+dx[k]][j+dy[k]]) && (y=id[i+dx[l]][j+dy[l]]))
						hsh.ins(getfa(x),getfa(y));
			}
	for (i=1; i<=gol; i++) fa0[i]=getfa(i);
	while (cas--){
		scanf("%d",&cnt);
		q[1]=sta; q[tp=2]=gol; vis[sta]=vis[gol]=1;
		if (!vis[fa[sta]]){ q[++tp]=fa[sta]; vis[fa[sta]]=1; }
		if (!vis[fa[gol]]){ q[++tp]=fa[gol]; vis[fa[gol]]=1; }
		for (i=1; i<=cnt; i++){
			scanf("%d%d",&bx[i],&by[i]);
			a[bx[i]][by[i]]='#';
			q[++tp]=x=id[bx[i]][by[i]]; vis[x]=1;
			for (k=0; k<8; k++) if (a[bx[i]+dx[k]][by[i]+dy[k]]=='#'){
				y=findfa(id[bx[i]+dx[k]][by[i]+dy[k]]);
				if (!vis[y]){ q[++tp]=y; vis[y]=1; }
				fa[findfa(x)]=y;
			}
			if (bx[i]==m || by[i]==1) fa[findfa(x)]=findfa(sta);
			if (bx[i]==1 || by[i]==n) fa[findfa(x)]=findfa(gol);
		}
		puts((ok())?"YES":"NO"); fflush(stdout);
		for (i=1; i<=cnt; i++) a[bx[i]][by[i]]='.';
		for (i=1; i<=tp; i++){
			vis[q[i]]=0; fa[q[i]]=fa0[q[i]];
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define N 1005
#define M 1000005
using namespace std;

int m,n,cas,cnt,tp,sta,gol,id[N][N],fa[M],fa0[M],bx[N],by[N],q[N],rt[N];
char a[N][N]; bool vis[M];
int dx[8]={-1,-1,-1,0,1,1,1,0},dy[8]={-1,0,1,1,1,0,-1,-1};
struct hsh_node{
	int tot,fst[2010527],px[M<<3],py[M<<3],nxt[M<<3];
	void ins(int x,int y){
		if (!x || !y) return;
		if (x>y) swap(x,y);
		int z=(x*233+y)%2010527,i;
		for (i=fst[z]; i; i=nxt[i]) if (px[i]==x && py[i]==y) return;
		px[++tot]=x; py[tot]=y; nxt[tot]=fst[z]; fst[z]=tot;
	}
	bool check(int x,int y){
		if (x>y) swap(x,y);
		int z=(x*233+y)%2010527,i;
		for (i=fst[z]; i; i=nxt[i]) if (px[i]==x && py[i]==y) return 1;
		return 0;
	}
}hsh;
int getfa(int x){ if (!x){puts("no!");while(1);}return (x==fa[x])?x:fa[x]=getfa(fa[x]); }
int findfa(int x){ return (x==fa[x])?x:getfa(fa[x]); }
bool ok(){
	int i,j,S=findfa(sta),T=findfa(gol);
	if (S==T) return 0;
	for (i=1; i<=tp; i++) rt[i]=findfa(q[i]);
	for (i=1; i<=tp; i++) if (rt[i]==S)
		for (j=1; j<=tp; j++) if (rt[j]==T && hsh.check(q[i],q[j])) return 0;
	return 1;
}
int main(){
	scanf("%d%d%d",&m,&n,&cas);
	int i,j,k,l,x,y;
	for (i=1; i<=m; i++) scanf("%s",a[i]+1);
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) id[i][j]=(i-1)*n+j;
	sta=m*n+1; gol=sta+1;
	for (i=1; i<=gol; i++) fa[i]=i;
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++) if (a[i][j]=='#'){
			x=id[i][j];
			for (k=0; k<8; k++)
				if (a[i+dx[k]][j+dy[k]]=='#')
					fa[getfa(x)]=getfa(id[i+dx[k]][j+dy[k]]);
			if (i==m || j==1) fa[getfa(x)]=getfa(sta);
			if (i==1 || j==n) fa[getfa(x)]=getfa(gol);
		}
	for (i=1; i<=m; i++)
		for (j=1; j<=n; j++){
			if (i+1==m || j==2) hsh.ins(getfa(sta),getfa(id[i][j]));
			if (i==2 || j+1==n) hsh.ins(getfa(gol),getfa(id[i][j]));
			for (k=0; k<8; k++)
				for (l=0; l<k; l++)
					if (abs(dx[k]-dx[l])==2 && abs(dy[k]-dy[l])==2 && (x=id[i+dx[k]][j+dy[k]]) && (y=id[i+dx[l]][j+dy[l]]))
						hsh.ins(getfa(x),getfa(y));
			}
	for (i=1; i<=gol; i++) fa0[i]=getfa(i);
	while (cas--){
		scanf("%d",&cnt);
		q[1]=sta; q[tp=2]=gol; vis[sta]=vis[gol]=1;
		for (i=1; i<=cnt; i++){
			scanf("%d%d",&bx[i],&by[i]);
			a[bx[i]][by[i]]='#';
			q[++tp]=x=id[bx[i]][by[i]]; vis[x]=1;
			for (k=0; k<8; k++) if (a[bx[i]+dx[k]][by[i]+dy[k]]=='#'){
				y=findfa(id[bx[i]+dx[k]][by[i]+dy[k]]);
				if (!vis[y]){ q[++tp]=y; vis[y]=1; }
				fa[findfa(x)]=y;
			}
			if (bx[i]==m || by[i]==1) fa[findfa(x)]=findfa(sta);
			if (bx[i]==1 || by[i]==n) fa[findfa(x)]=findfa(gol);
		}
		puts((ok())?"YES":"NO"); fflush(stdout);
		for (i=1; i<=cnt; i++) a[bx[i]][by[i]]='.';
		for (i=1; i<=tp; i++){
			vis[q[i]]=0; fa[q[i]]=fa0[q[i]];
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1010, dx[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy[] = {1, 1, 0, -1, -1, -1, 0, 1} ;
int n, m, q;
char s[N][N];

int id[N][N], f[N * N], l = 0, S, T;

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int Fx(int x) { return f[x] == x ? x : Fx(f[x]); }
#define ii i + dx[k]
#define jj j + dy[k]
#define x id[i][j]
#define y id[ii][jj]

bool ch[N], haveans = true;
set< pair<int, int> > frb;

pair<int, int> get(int a, int b) {
	if (a < b) swap(a, b); return mp(a,b);
}

void init() {
	rep(i,1,n) rep(j,1,m) id[i][j] = ++l, f[id[i][j]] = id[i][j];
	S = ++l, T = ++l;  f[S] = S, f[T] = T;
	rep(j,1,m) id[0][j] = S, id[n + 1][j] = T, s[0][j] = s[n + 1][j] = '#';
	rep(i,1,n) id[i][0] = T, id[i][m + 1] = S, s[i][0] = s[i][m + 1] = '#';
	s[1][1] = 'S', s[n][m] = 'T';
	rep(i,1,n) rep(j,1,m) if (s[i][j] == '#') {
		rep(k,0,7) if (s[ii][jj] == '#') {
			int fx = find(x), fy = find(y);
			f[fx] = fy;
		}
	}
	rep(i,1,n) rep(j,1,m) if (s[i][j] == '.') {
		rep(k1,0,7) rep(k2,k1 + 1,7) {
			int k, t1, t2;
			k = k1, t1 = find(y); k = k2, t2 = find(y);
			frb.insert(get(t1, t2));
		}
	}
	rep(i,1,n) rep(j,1,m) if (s[i][j] == '.' || s[i][j] == '#') {
		rep(k1,0,7) rep(k2,0,7) {
			int k, t1, t2;
			k = k1, t1 = find(y); k = k2, t2 = find(y);
			if (t1 == find(S) && t2 == find(T)) haveans = false;
		}
	}
}

int k, ndx[11], ndy[11];
int bk[110], fa[110];

void work() {
	scanf("%d",&k); rep(i,1,k) scanf("%d%d",&ndx[i],&ndy[i]);
	rep(i,1,k) s[ndx[i]][ndy[i]] = '#';
	bool ans = haveans; int l = 0;
	rep(t,1,k) {
		int i = ndx[t], j = ndy[t]; bk[++l] = find(x);
		rep(k,0,7) if (s[ii][jj] == '#') bk[++l] = find(y);
	}
	bk[++l] = find(S), bk[++l] = find(T);
	sort(bk + 1, bk + l + 1); l = unique(bk + 1, bk + l + 1) - bk - 1;
	rep(i,1,l) fa[i] = find(bk[i]);

	rep(t,1,k) {
		int i = ndx[t], j = ndy[t];
		rep(k,0,7) if (s[ii][jj] == '#') {
			int fx = Fx(x), fy = Fx(y);
			if (fx != fy) f[fx] = fy;
		}
	}

	if (Fx(S) == Fx(T)) ans = false;
	rep(i,1,l) {
		if (!ans) break;
		rep(j,1,l) if (Fx(bk[i]) == Fx(S) && Fx(bk[j]) == Fx(T) && frb.find(get(bk[i], bk[j])) != frb.end()) {
			ans = false; break;
		}
	}

	rep(i,1,l) f[bk[i]] = fa[i];
	rep(i,1,k) s[ndx[i]][ndy[i]] = '.';
	if (ans) printf("YES\n"); else printf("NO\n"); fflush(stdout);

}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	rep(i,1,n) scanf("%s",s[i] + 1);
	init(); rep(i,1,q) work();
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
#define mp make_pair

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[1010][1010];
int fa[N],dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1},n,m,q,S,T,k,bx[20],by[20],st[N],tp,id[1010][1010],tt;
set<pii> all;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int getf2(int x) {
	return x==fa[x]?x:getf2(fa[x]);
}

pii mp2(int x,int y) {
	return mp(min(x,y),max(x,y));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) id[i][j]=++tt;
	}
	S=++tt;T=++tt;
	for(int i=1;i<=tt;i++) fa[i]=i;
	for(int i=1;i<=n;i++) id[i][0]=S,id[i][m+1]=T,s[i][0]=s[i][m+1]='#';
	for(int i=1;i<=m;i++) id[0][i]=T,id[n+1][i]=S,s[0][i]=s[n+1][i]='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')
				for(int d=0;d<8;d++) {
					int x=i+dx[d],y=j+dy[d];
					if(s[x][y]=='#') fa[getf(id[i][j])]=getf(id[x][y]);
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			if(i+j==2||i+j==n+m) continue;
			for(int d1=0;d1<8;d1++)
				for(int d2=d1+1;d2<8;d2++) {
					int x1=i+dx[d1],y1=j+dy[d1],x2=i+dx[d2],y2=j+dy[d2];
					all.insert(mp2(getf(id[x1][y1]),getf(id[x2][y2])));
				}
		}
	//cerr<<getf(S);
	//cerr<<(all.find(mp(232,280))==all.end());
	//cerr<<getf(T);
	for(int i=1;i<=tt;i++) getf(i);
	while(q--) {
		k=gi();tp=0;
		for(int i=1;i<=k;i++) {
			bx[i]=gi(),by[i]=gi();s[bx[i]][by[i]]='#';
			st[++tp]=getf(id[bx[i]][by[i]]);
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') st[++tp]=getf(id[x][y]);
			}
		}
		st[++tp]=getf(S);st[++tp]=getf(T);
		sort(st+1,st+tp+1);
		tp=unique(st+1,st+tp+1)-st-1;
		for(int i=1;i<=k;i++)
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') {
					//cerr<<bx[i]<<' '<<by[i]<<' '<<x<<' '<<y<<' '<<getf2(id[bx[i]][by[i]])<<' '<<getf2(id[x][y])<<'\n';
					fa[getf2(id[bx[i]][by[i]])]=getf2(id[x][y]);
				}
			}
		bool ans=1;
		if(getf2(S)==getf2(T)) ans=0;
		//cerr<<getf2(T)<<' '<<getf2(id[8][15])<<'\n';
		for(int i=1;i<=tp&&ans;i++)
			if(getf2(st[i])==getf(S))
				for(int j=1;j<=tp&&ans;j++)
					if(getf2(st[j])==getf(T)&&all.find(mp2(st[i],st[j]))!=all.end()) ans=0;
		cout<<(ans?"YES":"NO")<<endl;
		for(int i=1;i<=k;i++) s[bx[i]][by[i]]='.';
		for(int i=1;i<=tp;i++) fa[st[i]]=st[i];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
#define mp make_pair

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[1010][1010];
int fa[N],dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1},n,m,q,S,T,k,bx[20],by[20],st[N],tp,id[1010][1010],tt;
set<pii> all;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int getf2(int x) {
	return x==fa[x]?x:getf2(fa[x]);
}

pii mp2(int x,int y) {
	return mp(min(x,y),max(x,y));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) id[i][j]=++tt;
	}
	S=++tt;T=++tt;
	for(int i=1;i<=tt;i++) fa[i]=i;
	for(int i=1;i<=n;i++) id[i][0]=S,id[i][m+1]=T,s[i][0]=s[i][m+1]='#';
	for(int i=1;i<=m;i++) id[0][i]=T,id[n+1][i]=S,s[0][i]=s[n+1][i]='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')
				for(int d=0;d<8;d++) {
					int x=i+dx[d],y=j+dy[d];
					if(s[x][y]=='#') fa[getf(id[i][j])]=getf(id[x][y]);
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			if(i+j==2||i+j==n+m) continue;
			for(int d1=0;d1<8;d1++)
				for(int d2=d1+1;d2<8;d2++) {
					int x1=i+dx[d1],y1=j+dy[d1],x2=i+dx[d2],y2=j+dy[d2];
					all.insert(mp2(getf(id[x1][y1]),getf(id[x2][y2])));
				}
		}
	//cerr<<getf(S);
	//cerr<<(all.find(mp(232,280))==all.end());
	//cerr<<getf(T);
	for(int i=1;i<=tt;i++) getf(i);
	while(q--) {
		k=gi();
		for(int i=1;i<=k;i++) {
			bx[i]=gi(),by[i]=gi();s[bx[i]][by[i]]='#';
			st[++tp]=getf(id[bx[i]][by[i]]);
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') st[++tp]=getf(id[x][y]);
			}
		}
		st[++tp]=getf(S);st[++tp]=getf(T);
		sort(st+1,st+tp+1);
		tp=unique(st+1,st+tp+1)-st-1;
		for(int i=1;i<=k;i++)
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') {
					//cerr<<bx[i]<<' '<<by[i]<<' '<<x<<' '<<y<<' '<<getf2(id[bx[i]][by[i]])<<' '<<getf2(id[x][y])<<'\n';
					fa[getf2(id[bx[i]][by[i]])]=getf2(id[x][y]);
				}
			}
		bool ans=1;
		if(getf2(S)==getf2(T)) ans=0;
		//cerr<<getf2(T)<<' '<<getf2(id[8][15])<<'\n';
		for(int i=1;i<=tp&&ans;i++)
			if(getf2(st[i])==getf(S))
				for(int j=1;j<=tp&&ans;j++)
					if(getf2(st[j])==getf(T)&&all.find(mp2(st[i],st[j]))!=all.end()) ans=0;
		cout<<(ans?"YES":"NO")<<endl;
		for(int i=1;i<=k;i++) s[bx[i]][by[i]]='.';
		for(int i=1;i<=tp;i++) fa[st[i]]=st[i];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
#define mp make_pair

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[1010][1010];
int fa[N],dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1},n,m,q,S,T,k,bx[20],by[20],st[N],tp,id[1010][1010],tt;
set<pii> all;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int getf2(int x) {
	return x==fa[x]?x:getf2(fa[x]);
}

pii mp2(int x,int y) {
	return mp(min(x,y),max(x,y));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) id[i][j]=++tt;
	}
	S=++tt;T=++tt;
	for(int i=1;i<=tt;i++) fa[i]=i;
	for(int i=1;i<=n;i++) id[i][0]=S,id[i][m+1]=T,s[i][0]=s[i][m+1]='#';
	for(int i=1;i<=m;i++) id[0][i]=T,id[n+1][i]=S,s[0][i]=s[n+1][i]='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')
				for(int d=0;d<8;d++) {
					int x=i+dx[d],y=j+dy[d];
					if(s[x][y]=='#') fa[getf(id[i][j])]=getf(id[x][y]);
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			if(i+j==2||i+j==n+m) continue;
			for(int d1=0;d1<8;d1++)
				for(int d2=d1+1;d2<8;d2++) {
					int x1=i+dx[d1],y1=j+dy[d1],x2=i+dx[d2],y2=j+dy[d2];
					all.insert(mp2(getf(id[x1][y1]),getf(id[x2][y2])));
				}
		}
	for(int i=1;i<=tt;i++) getf(i);
	while(q--) {
		k=gi();tp=0;
		for(int i=1;i<=k;i++) {
			bx[i]=gi(),by[i]=gi();s[bx[i]][by[i]]='#';
			st[++tp]=getf(id[bx[i]][by[i]]);
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') st[++tp]=getf(id[x][y]);
			}
		}
		st[++tp]=getf(S);st[++tp]=getf(T);
		sort(st+1,st+tp+1);
		tp=unique(st+1,st+tp+1)-st-1;
		for(int i=1;i<=k;i++)
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') {
					fa[getf2(id[x][y])]=getf2(id[bx[i]][by[i]]);
					//fa[getf2(id[bx[i]][by[i]])]=getf2(id[x][y]);
				}
			}
		bool ans=1;
		if(getf2(S)==getf2(T)) ans=0;
		for(int i=1;i<=tp&&ans;i++)
			if(getf2(st[i])==getf(S))
				for(int j=1;j<=tp&&ans;j++)
					if(getf2(st[j])==getf(T)&&all.find(mp2(st[i],st[j]))!=all.end()) ans=0;
		cout<<(ans?"YES":"NO")<<endl;
		for(int i=1;i<=k;i++) s[bx[i]][by[i]]='.';
		for(int i=1;i<=tp;i++) fa[st[i]]=st[i];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
#define mp make_pair

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[1010][1010];
int fa[N],dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1},n,m,q,S,T,k,bx[20],by[20],st[N],tp,id[1010][1010],tt;
set<pii> all;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int getf2(int x) {
	return x==fa[x]?x:getf2(fa[x]);
}

pii mp2(int x,int y) {
	return mp(min(x,y),max(x,y));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) id[i][j]=++tt;
	}
	S=++tt;T=++tt;
	for(int i=1;i<=tt;i++) fa[i]=i;
	for(int i=1;i<=n;i++) id[i][0]=S,id[i][m+1]=T,s[i][0]=s[i][m+1]='#';
	for(int i=1;i<=m;i++) id[0][i]=T,id[n+1][i]=S,s[0][i]=s[n+1][i]='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')
				for(int d=0;d<8;d++) {
					int x=i+dx[d],y=j+dy[d];
					if(s[x][y]=='#') fa[getf(id[i][j])]=getf(id[x][y]);
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			if(i+j==2||i+j==n+m) continue;
			for(int d1=0;d1<8;d1++)
				for(int d2=d1+1;d2<8;d2++) {
					int x1=i+dx[d1],y1=j+dy[d1],x2=i+dx[d2],y2=j+dy[d2];
					all.insert(mp2(getf(id[x1][y1]),getf(id[x2][y2])));
				}
		}
	for(int i=1;i<=tt;i++) getf(i);
	while(q--) {
		k=gi();tp=0;
		for(int i=1;i<=k;i++) {
			bx[i]=gi(),by[i]=gi();s[bx[i]][by[i]]='#';
			st[++tp]=getf(id[bx[i]][by[i]]);
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') st[++tp]=getf(id[x][y]);
			}
		}
		st[++tp]=getf(S);st[++tp]=getf(T);
		sort(st+1,st+tp+1);
		tp=unique(st+1,st+tp+1)-st-1;
		for(int i=1;i<=k;i++)
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') {
					fa[getf2(id[bx[i]][by[i]])]=getf2(id[x][y]);
				}
			}
		bool ans=1;
		if(getf2(S)==getf2(T)) ans=0;
		for(int i=1;i<=tp&&ans;i++)
			if(getf2(st[i])==getf2(S))
				for(int j=1;j<=tp&&ans;j++)
					if(getf2(st[j])==getf2(T)&&all.find(mp2(st[i],st[j]))!=all.end()) ans=0;
		cout<<(ans?"YES":"NO")<<endl;
		for(int i=1;i<=k;i++) s[bx[i]][by[i]]='.';
		for(int i=1;i<=tp;i++) fa[st[i]]=st[i];
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef pair<int,int> pii;
#define mp make_pair

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

char s[1010][1010];
int fa[N],dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1},n,m,q,S,T,k,bx[20],by[20],st[N],tp,id[1010][1010],tt;
set<pii> all;

int getf(int x) {
	return x==fa[x]?x:fa[x]=getf(fa[x]);
}

int getf2(int x) {
	return x==fa[x]?x:getf2(fa[x]);
}

pii mp2(int x,int y) {
	return mp(min(x,y),max(x,y));
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("a.in","r",stdin);
	freopen("a.out","w",stdout);
#endif
	cin>>n>>m>>q;
	for(int i=1;i<=n;i++) {
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++) id[i][j]=++tt;
	}
	S=++tt;T=++tt;
	for(int i=1;i<=tt;i++) fa[i]=i;
	for(int i=1;i<=n;i++) id[i][0]=S,id[i][m+1]=T,s[i][0]=s[i][m+1]='#';
	for(int i=1;i<=m;i++) id[0][i]=T,id[n+1][i]=S,s[0][i]=s[n+1][i]='#';
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')
				for(int d=0;d<8;d++) {
					int x=i+dx[d],y=j+dy[d];
					if(s[x][y]=='#') fa[getf(id[i][j])]=getf(id[x][y]);
				}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) {
			if(i+j==2||i+j==n+m) continue;
			for(int d1=0;d1<8;d1++)
				for(int d2=d1+1;d2<8;d2++) {
					int x1=i+dx[d1],y1=j+dy[d1],x2=i+dx[d2],y2=j+dy[d2];
					all.insert(mp2(getf(id[x1][y1]),getf(id[x2][y2])));
				}
		}
	for(int i=1;i<=tt;i++) getf(i);
	while(q--) {
		k=gi();tp=0;
		for(int i=1;i<=k;i++) {
			bx[i]=gi(),by[i]=gi();s[bx[i]][by[i]]='#';
			st[++tp]=getf(id[bx[i]][by[i]]);
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') st[++tp]=getf(id[x][y]);
			}
		}
		st[++tp]=getf(S);st[++tp]=getf(T);
		sort(st+1,st+tp+1);
		tp=unique(st+1,st+tp+1)-st-1;
		for(int i=1;i<=k;i++)
			for(int d=0;d<8;d++) {
				int x=bx[i]+dx[d],y=by[i]+dy[d];
				if(s[x][y]=='#') {
					fa[getf2(id[x][y])]=fa[getf2(id[bx[i]][by[i]])];
					//fa[getf2(id[bx[i]][by[i]])]=getf2(id[x][y]);
				}
			}
		bool ans=1;
		if(getf2(S)==getf2(T)) ans=0;
		for(int i=1;i<=tp&&ans;i++)
			if(getf2(st[i])==getf(S))
				for(int j=1;j<=tp&&ans;j++)
					if(getf2(st[j])==getf(T)&&all.find(mp2(st[i],st[j]))!=all.end()) ans=0;
		cout<<(ans?"YES":"NO")<<endl;
		for(int i=1;i<=k;i++) s[bx[i]][by[i]]='.';
		for(int i=1;i<=tp;i++) fa[st[i]]=st[i];
	}
	return 0;
}