#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int n;
int k[3];
int s[2][7005];
int ct[2][7005][5];
int dp[2][7005];
struct node
{
    int f,id,ty;
};
void spfa()
{
    node sta1,sta2;
    sta1.f=0,sta1.id=0,sta1.ty=3;
    sta2.f=1,sta2.id=0,sta2.ty=3;

    queue<node> q;
    q.push(sta1);
    q.push(sta2);

    while(!q.empty())
    {
        //cout<<"died"<<endl;
        node cur=q.front();
        q.pop();

        int f=cur.f;
        for(int i=0;i<k[1-f];i++)
        {
            int nf=1-f;
            int nid=(((cur.id-s[nf][i])%n)+n)%n;

            if(dp[nf][nid]!=0)
            {
                continue;
            }

            ct[nf][nid][cur.ty]++;

            if(ct[nf][nid][3]>0)
            {
                dp[nf][nid]=1;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=1;
                q.push(nex);
            }
            else if(ct[nf][nid][1]==k[nf])
            {
                dp[nf][nid]=3;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=3;
                q.push(nex);
            }
        }

    }

}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(ct,0,sizeof(ct));
        memset(dp,0,sizeof(dp));
        scanf("%d",&k[0]);
        for(int i=0;i<k[0];i++)
        {
            scanf("%d",&s[0][i]);
        }
        scanf("%d",&k[1]);
        for(int i=0;i<k[1];i++)
        {
            scanf("%d",&s[1][i]);
        }
        //cout<<"1"<<endl;
        spfa();
        //cout<<"2"<<endl;
        for(int i=1;i<n;i++)
        {
            if(dp[0][i]==0)
            {
                dp[0][i]=2;
            }
            int tp=dp[0][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");

        for(int i=1;i<n;i++)
        {
            if(dp[1][i]==0)
            {
                dp[1][i]=2;
            }
            int tp=dp[1][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");
    }
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
int n;
int k[3];
int s[2][7005];
int ct[2][7005][5];
int dp[2][7005];
struct node
{
    int f,id,ty;
};
void spfa()
{
    node sta1,sta2;
    sta1.f=0,sta1.id=0,sta1.ty=3;
    sta2.f=1,sta2.id=0,sta2.ty=3;

    queue<node> q;
    q.push(sta1);
    q.push(sta2);

    while(!q.empty())
    {
        //cout<<"died"<<endl;
        node cur=q.front();
        q.pop();

        int f=cur.f;
        for(int i=0;i<k[1-f];i++)
        {
            int nf=1-f;
            int nid=(((cur.id-s[nf][i])%n)+n)%n;

            if(dp[nf][nid]!=0)
            {
                continue;
            }

            ct[nf][nid][cur.ty]++;

            if(ct[nf][nid][3]>0)
            {
                dp[nf][nid]=1;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=1;
                q.push(nex);
            }
            else if(ct[nf][nid][1]==k[nf])
            {
                dp[nf][nid]=3;
                node nex;
                nex.f=nf,nex.id=nid,nex.ty=3;
                q.push(nex);
            }
        }

    }

}
int main()
{
    while(~scanf("%d",&n))
    {
        memset(ct,0,sizeof(ct));
        memset(dp,0,sizeof(dp));
        scanf("%d",&k[0]);
        for(int i=0;i<k[0];i++)
        {
            scanf("%d",&s[0][i]);
        }
        scanf("%d",&k[1]);
        for(int i=0;i<k[1];i++)
        {
            scanf("%d",&s[1][i]);
        }
        //cout<<"1"<<endl;
        spfa();
        //cout<<"2"<<endl;
        for(int i=1;i<n;i++)
        {
            if(dp[0][i]==0)
            {
                if(ct[0][i][3]>0)
                {
                    dp[0][i]=1;
                }
                else if(ct[0][i][1]==k[0])
                {
                    dp[0][i]=3;
                }
                else
                    dp[0][i]=2;
            }
            int tp=dp[0][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");

        for(int i=1;i<n;i++)
        {
            if(dp[1][i]==0)
            {
                if(ct[1][i][3]>0)
                {
                    dp[1][i]=1;
                }
                else if(ct[1][i][1]==k[1])
                {
                    dp[1][i]=3;
                }
                else
                    dp[1][i]=2;
            }
            int tp=dp[1][i];
            if(tp==1)
                printf("Win ");
            else if(tp==3)
                printf("Lose ");
            else
                printf("Loop ");
        }
        printf("\n");
    }
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <list>
#include <queue>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

//#define _LOCAL_DEBUG_
#ifdef _LOCAL_DEBUG_
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

const int MAX = 7010;
int n[2], nPos, a[2][MAX];
int dp[2][MAX] = { 0 };
set<int> de[2][MAX], re[2][MAX];
queue<pii> q;

void clear() {
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < MAX; i++)
		for (int j = 0; j < 2; j++)
			de[j][i].clear(), re[j][i].clear();
}

void remove(int iPlayer, int iPos) {

	for (auto to : de[iPlayer][iPos]) re[1 - iPlayer][to].erase(iPos);

	if (dp[iPlayer][iPos] == -1)
		for (auto from : re[iPlayer][iPos]) {
			dp[1 - iPlayer][from] = 1;
			q.push({ 1 - iPlayer, from });
		}
	else
		for (auto from : re[iPlayer][iPos]) {
			de[1 - iPlayer][from].erase(iPos);
			if (de[1 - iPlayer][from].size() == 0) {
				dp[1 - iPlayer][from] = -1;
				q.push({ 1 - iPlayer, from });
			}
		}
	de[iPlayer][iPos].clear();
	re[iPlayer][iPos].clear();
}

void solve() {
	scanf("%d", &n[0]);
	for (int i = 0; i < n[0]; i++) scanf("%d", &a[0][i]);
	scanf("%d", &n[1]);
	for (int i = 0; i < n[1]; i++) scanf("%d", &a[1][i]);

	for (int iPlayer = 0; iPlayer < 2; iPlayer++)
		for (int iPos = 0; iPos < nPos; iPos++)
			for (int i = 0; i < n[iPlayer]; i++) {
				int oPos = (iPos + a[iPlayer][i]) % nPos;
				int oPlayer = 1 - iPlayer;
				de[iPlayer][iPos].insert(oPos);
				re[oPlayer][oPos].insert(iPos);
			}

	dp[0][0] = dp[1][0] = -1;
	q.push({ 0, 0 });
	q.push({ 1, 0 });
	while (q.size()) {
		int iPlayer = q.front().first, iPos = q.front().second;
		q.pop();
		remove(iPlayer, iPos);
	}

	for (int j = 0; j < 2; j++) {
		for (int i = 1; i < nPos; i++) printf(dp[j][i] == -1 ? "Lose " : dp[j][i] == 0 ? "Loop " : "Win ");
		printf("\n");
	}
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &nPos) == 1) {
		clear();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <list>
#include <queue>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

//#define _LOCAL_DEBUG_
#ifdef _LOCAL_DEBUG_
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

const int MAX = 7010;
int n[2], nPos, a[2][MAX];
int dp[2][MAX] = { 0 };
int c[2][MAX] = { 0 };
int u[2][MAX];
queue<pii> q;

void clear() {
	memset(dp, 0, sizeof(dp));
	memset(u, 0, sizeof(u));
	memset(c, 0, sizeof(c));
}

void remove(int iPlayer, int iPos) {
	for (int i = 0; i < n[1 - iPlayer]; i++) {
		int from = (iPos + nPos - a[1 - iPlayer][i]) % nPos;
		if(!u[1 - iPlayer][from])
			if (dp[iPlayer][iPos] == -1) {
				dp[1 - iPlayer][from] = 1;
				u[1 - iPlayer][from] = 1;
				q.push({ 1 - iPlayer, from });
			}
			else {
				c[1 - iPlayer][from]--;
				if(c[1 - iPlayer][from] == 0) {
					dp[1 - iPlayer][from] = -1;
					u[1 - iPlayer][from] = 1;
					q.push({ 1 - iPlayer, from });
				}
			}
	}
	c[iPlayer][iPos] = 0;
}

void solve() {
	scanf("%d", &n[0]);
	for (int i = 0; i < n[0]; i++) scanf("%d", &a[0][i]);
	scanf("%d", &n[1]);
	for (int i = 0; i < n[1]; i++) scanf("%d", &a[1][i]);

	for (int iPlayer = 0; iPlayer < 2; iPlayer++)
		for (int iPos = 0; iPos < nPos; iPos++)
			c[iPlayer][iPos] = n[iPlayer];

	dp[0][0] = dp[1][0] = -1;
	q.push({ 0, 0 });
	q.push({ 1, 0 });
	while (q.size()) {
		int iPlayer = q.front().first, iPos = q.front().second;
		q.pop();
		remove(iPlayer, iPos);
	}

	for (int j = 0; j < 2; j++) {
		for (int i = 1; i < nPos; i++) printf(dp[j][i] == -1 ? "Lose " : dp[j][i] == 0 ? "Loop " : "Win ");
		printf("\n");
	}
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &nPos) == 1) {
		clear();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <list>
#include <queue>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

//#define _LOCAL_DEBUG_
#ifdef _LOCAL_DEBUG_
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

const int MAX = 10000;
int n[2], nPos, a[2][MAX];
int dp[2][MAX] = { 0 };
set<int> de[2][MAX], re[2][MAX];
queue<pii> q;

void clear() {
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < MAX; i++)
		for (int j = 0; j < 2; j++)
			de[j][i].clear(), re[j][i].clear();
}

void remove(int iPlayer, int iPos) {

	for (auto to : de[iPlayer][iPos]) re[1 - iPlayer][to].erase(iPos);

	if (dp[iPlayer][iPos] == -1)
		for (auto from : re[iPlayer][iPos]) {
			dp[1 - iPlayer][from] = 1;
			q.push({ 1 - iPlayer, from });
		}
	else
		for (auto from : re[iPlayer][iPos]) {
			de[1 - iPlayer][from].erase(iPos);
			if (de[1 - iPlayer][from].size() == 0) {
				dp[1 - iPlayer][from] = -1;
				q.push({ 1 - iPlayer, from });
			}
		}
	de[iPlayer][iPos].clear();
	re[iPlayer][iPos].clear();
}

void solve() {
	scanf("%d", &n[0]);
	for (int i = 0; i < n[0]; i++) scanf("%d", &a[0][i]);
	scanf("%d", &n[1]);
	for (int i = 0; i < n[1]; i++) scanf("%d", &a[1][i]);

	for (int iPlayer = 0; iPlayer < 2; iPlayer++)
		for (int iPos = 0; iPos < nPos; iPos++)
			for (int i = 0; i < n[iPlayer]; i++) {
				int oPos = (iPos + a[iPlayer][i]) % nPos;
				int oPlayer = 1 - iPlayer;
				de[iPlayer][iPos].insert(oPos);
				re[oPlayer][oPos].insert(iPos);
			}

	dp[0][0] = dp[1][0] = -1;
	q.push({ 0, 0 });
	q.push({ 1, 0 });
	while (q.size()) {
		int iPlayer = q.front().first, iPos = q.front().second;
		q.pop();
		remove(iPlayer, iPos);
	}

	for (int j = 0; j < 2; j++) {
		for (int i = 1; i < nPos; i++) printf(dp[j][i] == -1 ? "Lose " : dp[j][i] == 0 ? "Loop " : "Win ");
		printf("\n");
	}
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &nPos) == 1) {
		clear();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <limits.h>
#include <vector>
#include <stdlib.h>
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>
#include <cassert>
#include <map>
#include <set>
#include <list>
#include <queue>

using namespace std;
typedef long long lli;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef long double ld;

const int INF = 0x3f3f3f3f;
const lli LINF = 0x3f3f3f3f3f3f3f3f;

//#define _LOCAL_DEBUG_
#ifdef _LOCAL_DEBUG_
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...)
#endif

const int MAX = 7010;
int n[2], nPos, a[2][MAX];
int dp[2][MAX] = { 0 };
set<int> de[2][MAX];
int u[2][MAX];
queue<pii> q;

void clear() {
	memset(dp, 0, sizeof(dp));
	memset(u, 0, sizeof(u));
	for (int i = 0; i < MAX; i++)
		for (int j = 0; j < 2; j++)
			de[j][i].clear();
}

void remove(int iPlayer, int iPos) {
	for (int i = 0; i < n[1 - iPlayer]; i++) {
		int from = (iPos + nPos - a[1 - iPlayer][i]) % nPos;
		if(!u[1 - iPlayer][from])
			if (dp[iPlayer][iPos] == -1) {
				dp[1 - iPlayer][from] = 1;
				u[1 - iPlayer][from] = 1;
				q.push({ 1 - iPlayer, from });
			}
			else {
				de[1 - iPlayer][from].erase(iPos);
				if(de[1 - iPlayer][from].size() == 0) {
					dp[1 - iPlayer][from] = -1;
					u[1 - iPlayer][from] = 1;
					q.push({ 1 - iPlayer, from });
				}
			}
	}
	de[iPlayer][iPos].clear();
}

void solve() {
	scanf("%d", &n[0]);
	for (int i = 0; i < n[0]; i++) scanf("%d", &a[0][i]);
	scanf("%d", &n[1]);
	for (int i = 0; i < n[1]; i++) scanf("%d", &a[1][i]);

	for (int iPlayer = 0; iPlayer < 2; iPlayer++)
		for (int iPos = 0; iPos < nPos; iPos++)
			for (int i = 0; i < n[iPlayer]; i++) {
				int oPos = (iPos + a[iPlayer][i]) % nPos;
				int oPlayer = 1 - iPlayer;
				de[iPlayer][iPos].insert(oPos);
			}

	dp[0][0] = dp[1][0] = -1;
	q.push({ 0, 0 });
	q.push({ 1, 0 });
	while (q.size()) {
		int iPlayer = q.front().first, iPos = q.front().second;
		q.pop();
		remove(iPlayer, iPos);
	}

	for (int j = 0; j < 2; j++) {
		for (int i = 1; i < nPos; i++) printf(dp[j][i] == -1 ? "Lose " : dp[j][i] == 0 ? "Loop " : "Win ");
		printf("\n");
	}
}

int main() {
#ifdef _LOCAL_VAN
	freopen("in.txt", "r", stdin);
#endif
	while (scanf("%d", &nPos) == 1) {
		clear();
		solve();
#ifndef _LOCAL_VAN
		return 0;
#endif
	}
	return 0;
}


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

#define N 7010

int rr, mm, r[N], m[N], n, f[N], g[N], flag;
char ans[][7] = {"Lose", "Loop", "Win"};

int func(int k) {
	return (k + n * n - 1) % n + 1;
}

int main() {
	scanf("%d", &n);
	scanf("%d", &rr);
	for (int i = 1; i <= rr; i ++) scanf("%d", &r[i]);
	scanf("%d", &mm);
	for (int i = 1; i <= mm; i ++) scanf("%d", &m[i]);
	memset(f, 0, sizeof f);
	memset(g, 0, sizeof g);
	f[1] = g[1] = -1;
    for (int i = 1; i <= rr; i ++) f[func(1-r[i])] = 1;
    for (int i = 1; i <= mm; i ++) g[func(1-m[i])] = 1;

    flag = 1;
		while (flag) {
			flag = 0;
			for (int j = 0; j > 1 - n; j --) if (f[func(j)] == 0) {
				int tag = 1;
				for (int i = 1; i <= rr && tag; i ++) if (g[func(j+r[i])] <= 0) tag = 0;
				if (tag) {
					flag = 1;
					f[func(j)] = -1;
					for (int i = 1; i <= mm; i ++) if (g[func(j-m[i])] == 0) g[func(j-m[i])] = 1;
				}
			}
		}
	for (int i = 2; i < n; i ++) printf("%s ", ans[f[i]+1]);puts(ans[f[n]+1]);
	for (int i = 2; i < n; i ++) printf("%s ", ans[g[i]+1]);puts(ans[g[n]+1]);
	return 0;
}


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

#define N 7010

int rr, mm, r[N], m[N], n, f[N], g[N], flag;
char ans[][7] = {"Lose", "Loop", "Win"};

int func(int k) {
	return (k + n * n - 1) % n + 1;
}

int main() {
	scanf("%d", &n);
	scanf("%d", &rr);
	for (int i = 1; i <= rr; i ++) scanf("%d", &r[i]);
	scanf("%d", &mm);
	for (int i = 1; i <= mm; i ++) scanf("%d", &m[i]);
	memset(f, 0, sizeof f);
	memset(g, 0, sizeof g);
	f[1] = g[1] = -1;
    for (int i = 1; i <= rr; i ++) f[func(1-r[i])] = 1;
    for (int i = 1; i <= mm; i ++) g[func(1-m[i])] = 1;
		flag = 1;

		while (flag) {

			flag = 0;
			for (int j = 0; j > 1 - n; j --) if (g[func(j)] == 0) {
				int tag = 1;
				for (int i = 1; i <= mm && tag; i ++) if (f[func(j+m[i])] <= 0) tag = 0;
				if (tag) {
					flag = 1;
					g[func(j)] = -1;
					for (int i = 1; i <= rr; i ++) if (f[func(j-r[i])] == 0) f[func(j-r[i])] = 1;
				}
			}
		}
		flag = 1;
		while (flag) {
			flag = 0;
			for (int j = 0; j > 1 - n; j --) if (f[func(j)] == 0) {
				int tag = 1;
				for (int i = 1; i <= rr && tag; i ++) if (g[func(j+r[i])] <= 0) tag = 0;
				if (tag) {
					flag = 1;
					f[func(j)] = -1;
					for (int i = 1; i <= mm; i ++) if (g[func(j-m[i])] == 0) g[func(j-m[i])] = 1;
				}
			}
		}

	for (int i = 2; i < n; i ++) printf("%s ", ans[f[i]+1]);puts(ans[f[n]+1]);
	for (int i = 2; i < n; i ++) printf("%s ", ans[g[i]+1]);puts(ans[g[n]+1]);
	return 0;
}


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

#define N 7010

int rr, mm, r[N], m[N], n, f[N], g[N], flag;
char ans[][7] = {"Lose", "Loop", "Win"};

int func(int k) {
	return (k + n * n - 1) % n + 1;
}

int main() {
	scanf("%d", &n);
	scanf("%d", &rr);
	for (int i = 1; i <= rr; i ++) scanf("%d", &r[i]);
	scanf("%d", &mm);
	for (int i = 1; i <= mm; i ++) scanf("%d", &m[i]);
	memset(f, 0, sizeof f);
	memset(g, 0, sizeof g);
	f[1] = g[1] = -1;
    for (int i = 1; i <= rr; i ++) f[func(1-r[i])] = 1;
    for (int i = 1; i <= mm; i ++) g[func(1-m[i])] = 1;
		flag = 1;

		while (flag) {
            for(int i=0;i<=8;i++)
            cout << f[i]<< " ";
        cout << "\n";
        for(int i=0;i<=8;i++)
            cout << g[i]<< " ";
        cout << "\n";
			flag = 0;
			for (int j = 0; j > 1 - n; j --) if (g[func(j)] == 0) {
				int tag = 1;
				for (int i = 1; i <= mm && tag; i ++) if (f[func(j+m[i])] <= 0) tag = 0;
				if (tag) {
					flag = 1;
					g[func(j)] = -1;
					for (int i = 1; i <= rr; i ++) if (f[func(j-r[i])] == 0) f[func(j-r[i])] = 1;
				}
			}
		}
		flag = 1;
		while (flag) {
			flag = 0;
			for (int j = 0; j > 1 - n; j --) if (f[func(j)] == 0) {
				int tag = 1;
				for (int i = 1; i <= rr && tag; i ++) if (g[func(j+r[i])] <= 0) tag = 0;
				if (tag) {
					flag = 1;
					f[func(j)] = -1;
					for (int i = 1; i <= mm; i ++) if (g[func(j-m[i])] == 0) g[func(j-m[i])] = 1;
				}
			}
		}

	for (int i = 2; i < n; i ++) printf("%s ", ans[f[i]+1]);puts(ans[f[n]+1]);
	for (int i = 2; i < n; i ++) printf("%s ", ans[g[i]+1]);puts(ans[g[n]+1]);
	return 0;
}


#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<cassert>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define rpe(i,r,l) for(int i=(r);i>=(l);--i)
#define rpp(i,x,e,head) for(int i=head[x];~i;i=e[i].next)
#define dyes cerr<<"yes"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1LL;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
template <class T> inline void chmax(T &a,T b){if(a<b) a=b;}
template <class T> inline void chmin(T &a,T b){if(a>b) a=b;}
inline void swap(int &a,int &b){int c=a;a=b;b=c;}
using namespace std;
#define mst(a,val) memset(a,val,sizeof(a))
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >
#define mp(i,j) make_pair(i,j)
#define fi first
#define sc second
#define inf (0x3f3f3f3f)
#define infll (0x3f3f3f3f3f3f3f3fLL)
#define id(i,j) ((i-1)*m+j)
const int N=7010;
int k[3],a[3][N],dp[3][N],wn[3][N];
pii q[N*2];
int n;
int main() {
    n=read();
    scanf("%d",&k[0]); rep(i,0,k[0]) scanf("%d",&a[0][i]);
    scanf("%d",&k[1]); rep(i,0,k[1]) scanf("%d",&a[1][i]);
    rep(i,1,n) wn[0][i]=k[0],wn[1][i]=k[1];
    memset(dp,-1,sizeof(dp));
    q[0]=mp(0,0);
    q[1]=mp(1,0);
    int t=2;
    dp[0][0]=dp[1][0]=0;
    rep(i,0,t) {
        int u=q[i].fi,v=q[i].sc;
        if (dp[u][v]==0) {
            rep(j,0,k[u^1]) {
                int uu=u^1,vv=(v+n-a[uu][j])%n;
                if (dp[uu][vv]==-1) {
                    dp[uu][vv]=1;
                    q[t++]=mp(uu,vv);
                }
            }
        } else {
            rep(j,0,k[u^1]) {
                int uu=u^1,vv=(v+n-a[uu][j])%n;
                --wn[uu][vv];
                if (dp[uu][vv]==-1&&wn[uu][vv]==0) {
                    dp[uu][vv]=0;
                    q[t++]=mp(uu,vv);
                }
            }

        }
    }
    rep(j,0,2) {
        rep(i,1,n) {
            if (dp[j][i]==-1)
                printf("Loop ");
            else if (dp[j][i]==0) printf("Lose ");
            else printf("Win ");
        }
        pts;
    }
    return 0;
}


#include<cstring>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<cassert>
using namespace std;
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define rpe(i,r,l) for(int i=(r);i>=(l);--i)
#define rpp(i,x,e,head) for(int i=head[x];~i;i=e[i].next)
#define dyes cerr<<"yes"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define pts puts("")
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
inline int read(){
    int f=1,x=0;char ch;
    do{ch=getchar();if(ch=='-')f=-1LL;}while(ch<'0'||ch>'9');
    do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
    return f*x;
}
template <class T> inline void chmax(T &a,T b){if(a<b) a=b;}
template <class T> inline void chmin(T &a,T b){if(a>b) a=b;}
inline void swap(int &a,int &b){int c=a;a=b;b=c;}
using namespace std;
#define mst(a,val) memset(a,val,sizeof(a))
#define pii pair<int,int>
#define piii pair<int,pair<int,int> >
#define mp(i,j) make_pair(i,j)
#define fi first
#define sc second
#define inf (0x3f3f3f3f)
#define infll (0x3f3f3f3f3f3f3f3fLL)
#define id(i,j) ((i-1)*m+j)
const int N=7010;
int k[3],a[3][N],f[3][N],wn[3][N];
pii q[N*2];
int n;
int main() {
    n=read();
    scanf("%d",&k[0]); rep(i,0,k[0]) scanf("%d",&a[0][i]);
    scanf("%d",&k[1]); rep(i,0,k[1]) scanf("%d",&a[1][i]);
    rep(i,1,n) wn[0][i]=k[0],wn[1][i]=k[1];
    memset(f,-1,sizeof(f));
    q[0]=mp(0,0);q[1]=mp(1,0);
    int t=2;
    f[0][0]=f[1][0]=0;
    rep(i,0,t) {
        int u=q[i].fi,v=q[i].sc;
        if (f[u][v]==0) {
            rep(j,0,k[u^1]) {
                int uu=u^1,vv=(v+n-a[uu][j])%n;
                if (f[uu][vv]==-1) {
                    f[uu][vv]=1;
                    q[t++]=mp(uu,vv);
                }
            }
        } else {
            rep(j,0,k[u^1]) {
                int uu=u^1,vv=(v+n-a[uu][j])%n;
                --wn[uu][vv];
                if (f[uu][vv]==-1&&wn[uu][vv]==0) {
                    f[uu][vv]=0;
                    q[t++]=mp(uu,vv);
                }
            }

        }
    }
    rep(j,0,1){
        rep(i,1,n-1){
            if(f[j][i]==-1)
                printf("Loop ");
            else if (f[j][i]==0) printf("Lose ");
            else printf("Win ");
        }
        pts;
    }
    return 0;
}


#include<iostream>
#include<list>
#include<set>
using namespace std;
const int N = 7000;
enum State
{
	WIN, LOSE, UNKNOWN
};

struct Node
{
	State state=UNKNOWN;
	//list<int> to;
	int to;
	int won = 0;//the amount of WIN state it targets to
	list<int> from;
};

Node RM[2 * N + 5];
//0~n-1 is Rick's next move, n~2*n-1 is Morty's next move
set<int> RickChoice;
set<int>MortyChoice;
int n;

void solve2(int u)
{
	void solve(int);
	for (int i : RM[u].from)
	{
		if (RM[i].state == UNKNOWN)
		{
			if ((++RM[i].won) == RM[i].to)
			{
				RM[i].state = LOSE;
				solve(i);
			}
		}
	}
}//To Responce when a Node is set to Win

void solve(int u)
{
	for (int i : RM[u].from)
	{
		if (RM[i].state ==UNKNOWN)
		{
			RM[i].state = WIN;
			solve2(i);
		}
	}
}//To Responce when a Node is set to Lost

int main()
{
	cin >> n;
	int rc, mc;
	cin >> rc;
	for (int i = 0; i < rc; i++)
	{
		int temp;
		cin >> temp;
		RickChoice.insert(temp);
	}
	cin >>mc;
	for (int i = 0; i < mc; i++)
	{
		int temp;
		cin >> temp;
		MortyChoice.insert(temp);
	}
	for (int i = 1; i < n; i++)
	{
		RM[i].to = rc;
		RM[i + n].to = mc;
		for (int j : RickChoice)
		{
			int t = (i + j) % n + n;
			//RM[i].to.push_back(t);
			RM[t].from.push_back(i);
		}
		for (int j : MortyChoice)
		{
			int t = (i + j) % n;
			//RM[i + n].to.push_back(t);
			RM[t].from.push_back(i + n);
		}
	}
	RM[0].state = RM[n].state = LOSE;
	solve(0);
	solve(n);
	for (int i = 1; i < n; i++)
	{
		switch (RM[i].state)
		{
		case WIN:cout << "Win ";
			break;
		case LOSE:cout << "Lose ";
			break;
		case UNKNOWN:cout << "Loop ";
			break;
		}
	}
	cout << endl;
	for (int i = n+1; i < 2*n; i++)
	{
		switch (RM[i].state)
		{
		case WIN:cout << "Win ";
			break;
		case LOSE:cout << "Lose ";
			break;
		case UNKNOWN:cout << "Loop ";
			break;
		}
	}
	cout << endl;
	return 0;
}


#include<iostream>
#include<list>
#include<set>
using namespace std;
const int N = 7000;
enum State
{
	WIN, LOSE, UNKNOWN
};

struct Node
{
	State state=UNKNOWN;
	//list<int> to;
	int to;
	int won = 0;//the amount of WIN state it targets to
	//list<int> from;
};

Node RM[2 * N + 5];
//0~n-1 is Rick's next move, n~2*n-1 is Morty's next move
set<int> RickChoice;
set<int>MortyChoice;
int n;

void solve2(int u)
{
	void solve(int);
	bool isrick = (u < n);
	if (isrick)
	{
		for (int j : MortyChoice)
		{
			int i = (u - j + 2 * n) % n + n;
			if (RM[i].state == UNKNOWN)
			{
				if ((++RM[i].won) == RM[i].to)
				{
					RM[i].state = LOSE;
					solve(i);
				}
			}
		}
	}
	else
	{
		for (int j : RickChoice)
		{
			int i = (u - j + 2 * n) % n;
			if (RM[i].state == UNKNOWN)
			{
				if ((++RM[i].won) == RM[i].to)
				{
					RM[i].state = LOSE;
					solve(i);
				}
			}
		}
	}
}//To Responce when a Node is set to Win

void solve(int u)
{
	bool isrick = (u < n);
	if (isrick)
	{
		for (int j : MortyChoice)
		{
			int i = (u - j + 2 * n) % n + n;
			if (RM[i].state == UNKNOWN)
			{
				RM[i].state = WIN;
				solve2(i);
			}
		}
	}
	else
	{
		for (int j :RickChoice)
		{
			int i = (u - j + 2 * n) % n;
			if (RM[i].state == UNKNOWN)
			{
				RM[i].state = WIN;
				solve2(i);
			}
		}
	}
}//To Responce when a Node is set to Lost

int main()
{
	cin >> n;
	int rc, mc;
	cin >> rc;
	for (int i = 0; i < rc; i++)
	{
		int temp;
		cin >> temp;
		RickChoice.insert(temp);
	}
	cin >>mc;
	for (int i = 0; i < mc; i++)
	{
		int temp;
		cin >> temp;
		MortyChoice.insert(temp);
	}
	for (int i = 1; i < n; i++)
	{
		RM[i].to = rc;
		RM[i + n].to = mc;
		//for (int j : RickChoice)
		//{
		//	int t = (i + j) % n + n;
			//RM[i].to.push_back(t);
		//	RM[t].from.push_back(i);
		//}
		//for (int j : MortyChoice)
		//{
		//	int t = (i + j) % n;
			//RM[i + n].to.push_back(t);
		//	RM[t].from.push_back(i + n);
		//}
	}
	RM[0].state = RM[n].state = LOSE;
	solve(0);
	solve(n);
	for (int i = 1; i < n; i++)
	{
		switch (RM[i].state)
		{
		case WIN:cout << "Win ";
			break;
		case LOSE:cout << "Lose ";
			break;
		case UNKNOWN:cout << "Loop ";
			break;
		}
	}
	cout << endl;
	for (int i = n+1; i < 2*n; i++)
	{
		switch (RM[i].state)
		{
		case WIN:cout << "Win ";
			break;
		case LOSE:cout << "Lose ";
			break;
		case UNKNOWN:cout << "Loop ";
			break;
		}
	}
	cout << endl;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e4 + 10;

int n;
vi s[2];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, 2) {
		int cnt;
		scanf("%d", &cnt);
		s[i].resize(cnt);
		forn(j, cnt) {
			scanf("%d", &s[i][j]);
		}
		sort(all(s[i]));
		s[i].resize(unique(all(s[i])) - s[i].begin());
	}
	return 1;
}

int dp[MAXN * 2];
int deg_out[MAXN * 2];

int code(int who, int pos) {
	return n * who + pos;
}

void solve() {
	memset (dp, -1, sizeof dp);
	memset (deg_out, 0, sizeof deg_out);

	queue<int> q;
	forn(who, 2) forn(pos, n) {
		int v = code(who, pos);
		if  (pos == 0) {
			dp[v] = 0;
			q.push(v);
		}
		deg_out[v] = sz(s[who]);
	}

	while (!q.empty()) {
		int v = q.front();
		q.pop();
		assert(dp[v] != -1);

		vi fr;
		int who = v / n;
		int pos = v % n;
		assert(code(who, pos) == v);
		for (int x : s[who ^ 1]) {
			int npos = (pos - x + n) % n;
			fr.pb(code(who ^ 1, npos));
		}

		for (int from : fr) {
			if  (dp[from] != -1) {
				continue;
			}
			if  (dp[v] == 0) {
				dp[from] = 1;
				q.push(from);
				continue;
			}
			if  (dp[v] == 1) {
				--deg_out[from];
				if  (deg_out[from] == 0) {
					dp[from] = 0;
					q.push(from);
				}
				continue;
			}
		}
	}

	forn(who, 2) {
		for (int pos = 1; pos < n; ++pos) {
			int v = code(who, pos);
			if  (dp[v] == 0) {
				printf("Lose ");
			} else if  (dp[v] == 1) {
				printf("Win ");
			} else {
				printf("Loop ");
			}
		}
		puts("");
	}
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		solve();
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 7e3 + 10;

int n;
vi s[2];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, 2) {
		int cnt;
		scanf("%d", &cnt);
		s[i].resize(cnt);
		forn(j, cnt) {
			scanf("%d", &s[i][j]);
		}
		sort(all(s[i]));
		s[i].resize(unique(all(s[i])) - s[i].begin());
	}
	return 1;
}

vi g[MAXN * 2];
vi gt[MAXN * 2];
int dp[MAXN * 2];
int deg_out[MAXN * 2];

void addE(int v, int to) {
	g[v].pb(to);
	gt[to].pb(v);
	++deg_out[v];
}

int code(int who, int pos) {
	return n * who + pos;
}

void solve() {
	forn(i, 2 * MAXN) {
		g[i].clear();
	}

	memset (dp, -1, sizeof dp);
	memset (deg_out, 0, sizeof deg_out);

	queue<int> q;
	forn(who, 2) forn(pos, n) {
		int v = code(who, pos);
		if  (pos == 0) {
			dp[v] = 0;
			q.push(v);
		} else {
			for (int x : s[who]) {
				addE(v, code(who ^ 1, (pos + x) % n));
			}
		}
	}

	while (!q.empty()) {
		int v = q.front();
		q.pop();
		assert(dp[v] != -1);

		for (int from : gt[v]) {
			if  (dp[from] != -1) {
				continue;
			}
			if  (dp[v] == 0) {
				dp[from] = 1;
				q.push(from);
				continue;
			}
			if  (dp[v] == 1) {
				--deg_out[from];
				if  (deg_out[from] == 0) {
					dp[from] = 0;
					q.push(from);
					continue;
				}
				continue;
			}
		}
	}

	forn(who, 2) {
		for (int pos = 1; pos < n; ++pos) {
			int v = code(who, pos);
			if  (dp[v] == 0) {
				printf("Lose ");
			} else if  (dp[v] == 1) {
				printf("Win ");
			} else {
				printf("Loop ");
			}
		}
		puts("");
	}
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		solve();
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#define FILE_NAME "a"

const int MAXN = 1e4 + 10;

int n;
vi s[2];

bool read() {
	if  (scanf("%d", &n) < 1) {
		return 0;
	}
	forn(i, 2) {
		int cnt;
		scanf("%d", &cnt);
		s[i].resize(cnt);
		forn(j, cnt) {
			scanf("%d", &s[i][j]);
		}
		sort(all(s[i]));
		s[i].resize(unique(all(s[i])) - s[i].begin());
	}
	return 1;
}

vi g[MAXN * 2];
vi gt[MAXN * 2];
int dp[MAXN * 2];
int deg_out[MAXN * 2];
bool was[MAXN * 2];

void addE(int v, int to) {
	g[v].pb(to);
	gt[to].pb(v);
}

int code(int who, int pos) {
	return n * who + pos;
}

void solve() {
	forn(i, 2 * MAXN) {
		g[i].clear();
	}

	memset (dp, -1, sizeof dp);
	memset (deg_out, 0, sizeof deg_out);
	memset (was, 0, sizeof was);

	queue<int> q;
	forn(who, 2) forn(pos, n) {
		int v = code(who, pos);
		if  (pos == 0) {
			dp[v] = 0;
			q.push(v);
			was[v] = 1;
		} else {
			for (int x : s[who]) {
				addE(v, code(who ^ 1, (pos + x) % n));
			}
		}
	}

	forn(v, 2 * n) {
		sort(all(g[v]));
		g[v].resize(unique(all(g[v])) - g[v].begin());

		sort(all(gt[v]));
		gt[v].resize(unique(all(gt[v])) - gt[v].begin());

		deg_out[v] = sz(g[v]);
	}

	while (!q.empty()) {
		int v = q.front();
		q.pop();
		assert(dp[v] != -1);

		for (int from : gt[v]) {
			if  (dp[from] != -1 || was[from]) {
				continue;
			}
			if  (dp[v] == 0) {
				dp[from] = 1;
				q.push(from);
				was[from] = 1;
				continue;
			}
			if  (dp[v] == 1) {
				--deg_out[from];
				if  (deg_out[from] == 0) {
					dp[from] = 0;
					q.push(from);
					was[from] = 1;
				}
				continue;
			}
		}
	}

	forn(who, 2) {
		for (int pos = 1; pos < n; ++pos) {
			int v = code(who, pos);
			if  (dp[v] == 0) {
				printf("Lose ");
			} else if  (dp[v] == 1) {
				printf("Win ");
			} else {
				printf("Loop ");
			}
		}
		puts("");
	}
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		solve();
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int mod(int n, int k)
{
	if(n%k){return n%k;}
	else {return k-(n%k);}
}

void shift(int l, int r, string& str)
{
	string sub;
	sub = str;
	str[l] = str[r];
	for(int i = l+1; i <= r; i++)
	{
		str[i] = sub[i - 1];
	}
}

int main(){

	string str;
	cin >> str;

	int m;
	cin >> m;

	for(int i = 0; i < m; i++)
	{
		int l, r, k;
		cin >>l >>r >> k;
		l--; r--;
		for(int j = 0; j < k; j++){shift(l, r, str);}
	}

	cout << str << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int mod(int n, int k)
{
	if(n%k){return n%k;}
	else {return k-(n%k);}
}

void shift(int l, int r, string& str)
{
	string sub;
	sub = str;
	str[l] = str[r];
	for(int i = l+1; i <= r; i++)
	{
		str[i] = sub[i - 1];
	}
}

int main(){

	string str;
	cin >> str;

	int m;
	cin >> m;

	for(int i = 0; i < m; i++)
	{
		int l, r, k;
		cin >>l >>r >> k;
		l--; r--; k = k % (r - l + 1);
		for(int j = 0; j < k; j++){shift(l, r, str);}
	}

	cout << str << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>

using namespace std;

int mod(int n, int k)
{
	if(n%k){return n%k;}
	else {return k-(n%k);}
}

void shift(int l, int r, int k, string& str)
{
	string sub;
	sub = str;
	for(int i = l; i < l + k; i++)
	{
		str[i] = sub[r + i - k + 1 - l];
	}
	for(int i = l + k; i <= r; i++)
	{
		str[i] = sub[i - k];
	}
}

int main(){

	string str;
	cin >> str;

	int m;
	cin >> m;

	for(int i = 0; i < m; i++)
	{
		int l, r, k;
		cin >>l >>r >> k;
		l--; r--; k = k % (r - l + 1);
		shift(l, r, k, str);
	}

	cout << str << endl;

	return 0;
}


//#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;

int main()
{
  string s, st; int m;
  cin >> s >> m;

  int l,r,k;

  for (int i = 0; i < m; i++) {
    cin >> l >> r >> k;
    //scanf("%i%i%i", &l, &r, &k);
    k = k % (r - l + 1);
    l = l - 1; r = r - 1;
    st=s;
    for (int j = 0; j <= (r-l); j++) {
      if ((j - k) >= 0) {
        st[ l + j ] = s[ l + j - k ];
      } else {
        st[ l + j ] = s[ r + j - k + 1 ];
      }
    }
    s = st;
  }
  cout << s;
  //cin >> s;
  return 0;
}


#include "stdafx.h"
#include <string>
#include <iostream>

using namespace std;

int main()
{
  string s, st; int m;
  cin >> s >> m;

  int l,r,k;

  for (int i = 0; i < m; i++) {
    scanf_s("%i%i%i", &l, &r, &k);
    k = k % (r - l + 1);
    l = l - 1; r = r - 1;
    st=s;
    for (int j = 0; j <= (r-l); j++) {
      if ((j - k) >= 0) {
        st[ l + j ] = s[ l + j - k ];
      } else {
        st[ l + j ] = s[ r + j - k + 1 ];
      }
    }
    s = st;
  }
  cout << s;
  cin >> s;
  return 0;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	string str;
	cin>>str;

	int m;
	cin>>m;
	while(m--)
	{
		int l,r,k;
		cin>>l>>r>>k;

		k%= r-l+1;

		string s = str.substr(l-1,r-l+1);

		for(int i=0;i<s.length();i++)
		{
			int x;
			x = (i+l-1+k);
			if(x>=r)
				x = x%r + l-1;
			str[x] = s[i];
		}
    }
	cout<<str<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	string str;
	cin>>str;

	int m;
	cin>>m;
	while(m--)
	{
		int l,r,k;
		cin>>l>>r>>k;

		k%= r-l+1;

		while(k--)
		{
			string s = str.substr(l-1,r-l+1);
			for(int i=0;i<s.length()-1;i++)
				swap(s[i],s[s.length()-1]);
			str = str.substr(0,l-1) + s + str.substr(r,str.length());
		}
	}
	cout<<str<<endl;

	return 0;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	string str;
	cin>>str;

	int m;
	cin>>m;
	while(m--)
	{
		int l,r,k;
		cin>>l>>r>>k;

		k%= r-l+1;

		while(k--)
		{
			for(int i=l;i<r;i++)
				swap(str[r-1],str[i-1]);
			//string s = str.substr(l-1,r-l+1);
			//str = str.substr(0,l-1) + s + str.substr(r,str.length());
		}
	}

	cout<<str<<endl;

	return 0;
}


#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define INF 0x3f3f3f3f
int main()
{
    char a[10005];
    scanf("%s", a + 1);
    int m, l, r, k, i, j, cnt = 0;
    scanf("%d", &m);
    char b[10005] = {0};
    char c[10005] = {0};
    for (i = 0; i < m; i++)
    {
        memset(b, 0, sizeof(b));
        cnt = 0;
        scanf("%d %d %d", &l, &r, &k);
        k = k % (r - l + 1);
        if (k == 0)
            continue;
        else
        {
            for (j = r - k + 1; j <= r; j++)
                b[cnt++] = a[j];
            for (j = l; j <= r - k; j++)
                b[cnt++] = a[j];
            for (j = l; j <= r; j++)
                a[j] = b[j - l];
        }
    }
    printf("%s\n", a + 1);
    //system("pause");
    return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<cstdio>
#include<bitset>
using namespace std;

#define Filesx
#define Timex
#define DEBUG

#ifdef DEBUG
#define DBG(x,s) cout<<s<<": "#x"="<<x<<"\n";
#else
#define DBG(x,s)
#endif
#define P(x) cout<<#x<<" = { "<<x<<" }\n"
#define All(a) (a).begin(), (a).end()
#define rep(i,n) for(int i=0;i<int(n);i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repi(i,a,n) for(int i=int(a);i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define dri(x) scanf("%d",&(x))
#define drii(x,y) scanf("%d%d",&(x),&(y))
#define drl(x) scanf("%I64d",&(x))
#define drll(x,y) scanf("%I64d%I64d",&(x),&(y))
#define mp(a, b) make_pair(a, b)
#define Odd(x) x%2!=0
#define Even(x) x%2==0
#define PI 3.1415926535897932384626433832795
#define INF 200000000ll
const double EPS = (1e-7);
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;   }

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, string> is;
typedef vector<pii> vii;

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }

//*---------------------------*/

void solution(){
	string s, temp;
	cin>>s;
	temp = s;
	int n, l, r, k;
	cin>>n;
	rep(i, n){
		cin>>l>>r>>k;
		l--; r--;
		k %= r-l+1;
		repi(j, l, r+1){
			int idx;
			if (j + k <= r) idx = j+k;
			else idx = j+k-r+l-1;
			temp[idx] = s[j];
		}
		repi(j, l, r+1){
			s[j] = temp[j];
		}
	}
	cout<<s;
}

//*---------------------------*/
int main(){
	#ifdef Files
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	double beg=clock();

	ios::sync_with_stdio(false);
	solution();

	#ifdef Time
	cout << endl;
	double end=clock();
	printf("*** Total time = %.3f sec ***", (end - beg) / CLOCKS_PER_SEC);
	#endif
	return 0;
}


#include<iostream>
#include<map>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<stack>
#include<math.h>
#include<set>
#include<string>
#include<cstring>
#include<queue>
#include<complex>
#include<cstdio>
#include<bitset>
using namespace std;

#define Filesx
#define Timex
#define DEBUG

#ifdef DEBUG
#define DBG(x,s) cout<<s<<": "#x"="<<x<<"\n";
#else
#define DBG(x,s)
#endif
#define P(x) cout<<#x<<" = { "<<x<<" }\n"
#define All(a) (a).begin(), (a).end()
#define rep(i,n) for(int i=0;i<int(n);i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define repi(i,a,n) for(int i=int(a);i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define clr(a, n) memset(a, n, sizeof(a));
#define scn(a,n) rep(i,n) cin>>a[i];
#define scn2(a,row,col) rep(i,row) rep(j,col) cin>>a[i][j];
#define prn(a,n) rep(i,n-1) cout<<a[i]<<" "; cout<<a[n-1]<<endl;
#define prn2(a,row,col) rep(i,row){rep(j,col-1) cout<<a[i][j]<<" "; cout<<a[i][col-1]<<endl;}
#define dri(x) scanf("%d",&(x))
#define drii(x,y) scanf("%d%d",&(x),&(y))
#define drl(x) scanf("%I64d",&(x))
#define drll(x,y) scanf("%I64d%I64d",&(x),&(y))
#define mp(a, b) make_pair(a, b)
#define Odd(x) x%2!=0
#define Even(x) x%2==0
#define PI 3.1415926535897932384626433832795
#define INF 200000000ll
const double EPS = (1e-7);
int dcmp(double x, double y) {  return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;   }

typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, string> is;
typedef vector<pii> vii;

ll gcd(ll a, ll b) { return (b == 0 ? a : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return (a * (b / gcd(a, b))); }

//*---------------------------*/

void solution(){
	string s, temp;
	cin>>s;
	temp = s;
	int n, l, r, k;
	cin>>n;
	rep(i, n){
		cin>>l>>r>>k;
		l--; r--;
		k %= r-l+1;
		repi(j, l, r+1){
			int idx;
			if (j + k <= r) idx = j+k;
			else idx = (j+k)%r+l-1;
			temp[idx] = s[j];
		}
		repi(j, l, r+1){
			s[j] = temp[j];
		}
	}
	cout<<s;
}

//*---------------------------*/
int main(){
	#ifdef Files
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	double beg=clock();

	ios::sync_with_stdio(false);
	solution();

	#ifdef Time
	cout << endl;
	double end=clock();
	printf("*** Total time = %.3f sec ***", (end - beg) / CLOCKS_PER_SEC);
	#endif
	return 0;
}


#include<cstdio>
#include<cstring>
#define LL long long
#define N 10005
using namespace std;

//int main() {
//  int t;
//  LL n, ans;
//  LL a;
//  scanf("%d", &t);
//  while (t--) {
//      scanf("%I64d", &n);
//      ans = (n*(n + 1)) / 2;
//      ans-=2;
//      a = 2;
//      while (a <= n) {
//          ans -= 2*a;
//          a *= 2;
//      }
//      printf("%I64d\n", ans);
//  }
//}

char str[N];
char word[N];

void swap(int l, int r, int k) {
    int len = r - l + 1;
    l--; r--;
    if(k>len)
    k = len%k;
    for (int p = r, i = 0; i < k; i++)
        word[i] = str[p--];
    for (int i = r-k; i >=l; i--)
        str[i+k] = str[i];
    for (int i = k-1; i >=0; i--)
        str[l++] = word[i];
}

int main() {
    int m;
    int l, r, k;
    while (scanf("%s", str) != EOF) {
        scanf("%d", &m);
        while (m--) {
            scanf("%d %d %d", &l, &r, &k);
            swap(l, r, k);
        }
        printf("%s\n", str);
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#define LL long long
#define N 10005
using namespace std;

//int main() {
//  int t;
//  LL n, ans;
//  LL a;
//  scanf("%d", &t);
//  while (t--) {
//      scanf("%I64d", &n);
//      ans = (n*(n + 1)) / 2;
//      ans-=2;
//      a = 2;
//      while (a <= n) {
//          ans -= 2*a;
//          a *= 2;
//      }
//      printf("%I64d\n", ans);
//  }
//}

char str[N];
char word[N];

void swap(int l, int r, int k) {
    int len = r - l + 1;
    l--; r--;
    if(k>len)
    k = k%len;
    for (int p = r, i = 0; i < k; i++)
        word[i] = str[p--];
    for (int i = r-k; i >=l; i--)
        str[i+k] = str[i];
    for (int i = k-1; i >=0; i--)
        str[l++] = word[i];
}

int main() {
    int m;
    int l, r, k;
    while (scanf("%s", str) != EOF) {
        scanf("%d", &m);
        while (m--) {
            scanf("%d %d %d", &l, &r, &k);
            swap(l, r, k);
        }
        printf("%s\n", str);
    }
    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
char s[10001];
char loc[10001];
int l,r,k,m;

int main() {
    scanf("%s",s);
	scanf("%d",&m);
	for (int i=0;i<m;i++)
	{
	    scanf("%d%d%d",&l,&r,&k);
	    int len=r-l+1;
	    for (int u=r-1;u>=r-k%len;u--)
	    {
	        loc[u]=s[u];
	    }
	    for (int q=r-1;q>=l-1+k%len;q--)
	    {
	        s[q]=s[q-k%len];
	    }
	    int g=r-k%len-l+1;
	    for (int p=l-1;p<l-1+k%len;p++)
	    {
	        s[p]=loc[p+g];
	    }
	}
	printf("%s",s);
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
char s[10001];
int l,r,k,m;

int main() {
    scanf("%s",s);
	scanf("%d",&m);
	for (int i=0;i<m;i++)
	{
	    scanf("%d%d%d",&l,&r,&k);
	    int len=r-l+1;
	    for (int j=0;j<k%len;j++)
	    {
	        if (len>1)
	        {
	            char x=s[r-1];
	            for (int q=r-1;q>=l;q--)
	            {
	                s[q]=s[q-1];
	            }
	            s[l-1]=x;
	        }
	    }
	    //printf("%s\n",s);
	}
	printf("%s",s);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<string>
#include<list>
#include<set>
#include<map>
#include<algorithm>

using namespace std;

#define fori(indFrom, indTo) for(int i = indFrom; i < indTo; i++)
#define forj(indFrom, indTo) for(int j = indFrom; j < indTo; j++)
#define cinVect(vect) { int tmp; cin >> tmp; vect.push_back(tmp); }
#define outVect(vect) { fori(0, vect.size()) { if (i > 0) cout << " "; cout << vect[i]; } cout << "\n"; }

char s[2][10010];

int main()
{
//	freopen("input.txt", "r", stdin);
	scanf("%s", &(s[0]));
	int m;
	scanf("%d", &m);
	int src = 0, dst = 1;
	fori(0, m)
	{
		int l, r, k;
		scanf("%d %d %d", &l, &r, &k);
		int l1 = r - l + 1;
		int ofs = k % l1;
		strcpy(s[dst], s[src]);
		for (int q = 0; q < l1; q++)
			s[dst][l - 1 + (q + ofs) % l1] = s[src][l + q - 1];
		src = (src + 1) % 2;
		dst = (dst + 1) % 2;
	}
	printf("%s\n", s[src]);
	//	freopen("out.txt", "w", stdout);
	return 0;
}


#include<iostream>
#include<stdio.h>
#include<vector>
#include<math.h>
#include<string>
#include<list>
#include<set>
#include<map>
#include<algorithm>

using namespace std;

#define fori(indFrom, indTo) for(int i = indFrom; i < indTo; i++)
#define forj(indFrom, indTo) for(int j = indFrom; j < indTo; j++)
#define cinVect(vect) { int tmp; cin >> tmp; vect.push_back(tmp); }
#define outVect(vect) { fori(0, vect.size()) { if (i > 0) cout << " "; cout << vect[i]; } cout << "\n"; }

char s[2][10000];

int main()
{
//	freopen("input.txt", "r", stdin);
	scanf("%s", &(s[0]));
	int m;
	scanf("%d", &m);
	int src = 0, dst = 1;
	fori(0, m)
	{
		int l, r, k;
		scanf("%d %d %d", &l, &r, &k);
		int l1 = r - l + 1;
		int ofs = k % l1;
		strcpy(s[dst], s[src]);
		for (int q = 0; q < l1; q++)
			s[dst][l - 1 + (q + ofs) % l1] = s[src][l + q - 1];
		src = (src + 1) % 2;
		dst = (dst + 1) % 2;
	}
	printf("%s\n", s[src]);
	//	freopen("out.txt", "w", stdout);
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	//freopen ("input.txt", "r", stdin);
	string s;
	cin >> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--, r--;
		k = k % (r - l + 1);
		rotate (s.begin() + l, s.begin() + r + 1 - k, s.begin() + r + 1);
	}
	cout << s << endl;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	//freopen ("input.txt", "r", stdin);
	string s;
	cin >> s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int l, r, k;
		cin >> l >> r >> k;
		l--, r--;
		k = k % (r - l + 1);
		s = s.substr (0, l) + s.substr (r - k + 1, k) + s.substr (l, (r - l + 1) - k) + s.substr (r + 1);
	}
	cout << s << endl;
}


#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;

int n;
char ch;
string test, sub, sub1, sub2, sub3, sub4, sub5;

int main()
{
	//freopen("i.txt", "r", stdin);
	//freopen("o.txt", "w", stdout);

	int len, le, ri, k, k2;
	cin >> test;

	scanf("%d", &n);

	while (n--)
	{
		scanf("%d%d%d", &le, &ri, &k);

		len = ri - le + 1;
		k = k%len;
		k2 = len - k;

		sub1 = test.substr(0, le - 1);
		sub2 = test.substr(le - 1, k2);
		sub3 = test.substr(le +k2- 1, k);
		sub3.reserve();
		sub4 = test.substr(ri);
		test = sub1 + sub3 + sub2 + sub4;
		cout << test << endl;
	}
	//system("pause");
	return 0;
}


#pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
using namespace std;

typedef long long ll;

int n;
char ch;
string test, sub, sub1, sub2, sub3, sub4, sub5;

int main()
{
    //freopen("i.txt", "r", stdin);
    //freopen("o.txt", "w", stdout);

    int len, le, ri, k, k2;
    cin >> test;

    scanf("%d", &n);

    while (n--)
    {
        scanf("%d%d%d", &le, &ri, &k);

        len = ri - le + 1;
        k = k%len;
        k2 = len - k;

        sub1 = test.substr(0, le - 1);
        sub2 = test.substr(le - 1, k2);
        sub3 = test.substr(le +k2- 1, k);
        sub3.reserve();
        sub4 = test.substr(ri);
        test = sub1 + sub3 + sub2 + sub4;
    }
    cout << test << endl;
    //system("pause");
    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

char s[10006];

void go(int l, int r, int k) {
		int len = (r - l + 1);
		k = k % len;
		for (int i = 0; i < k; i++) {
				char tm = s[r];
				for (int i = r; i > l; i--)
						s[i] = s[i - 1];

				s[l] = tm;
		}
}

int main() {
		scanf("%s", s + 1);
		int m;
		scanf("%d", &m);
		int l, r, k;
		while (m--) {
				scanf("%d %d %d", &l, &r, &k);
				go(l, r, k);
		}
		for (int i = 1; s[i] != '\0'; i++)
				printf("%c", s[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

int ar1[255], ar2[255];

void go(string &s, int l, int r, int k) {
		int len = (r - l + 1);
		k = k % len;
		for (int i = 0; i < k; i++) {
				char tm = s[r];
				for (int i = r; i > l; i--)
						s[i] = s[i - 1];

				s[l] = tm;
		}
}

int main() {
		string s;
		cin >> s;
		s = " " + s;
		int m;
		cin >> m;
		int l, r, k;
		while (m--) {
				cin >> l >> r >> k;
				go(s, l, r, k);
		}
		for (int i = 1; i < s.size(); i++)
				cout << s[i];
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

int ar1[255], ar2[255];

void go(string &s, int l, int r, int k) {
		int len = (l - r + 1);
		k = k % len;
		for (int i = 0; i < k; i++) {
				char tm = s[r];
				for (int i = l + 1; i <= r; i++)
						s[i] = s[i - 1];
				s[l] = tm;
		}
}

int main() {
		string s;
		cin >> s;
		s = " " + s;
		int m;
		cin >> m;
		int l, r, k;
		while (m--) {
				cin >> l >> r >> k;
				go(s, l, r, k);
		}
		for (int i = 1; i < s.size(); i++)
				cout << s[i];
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

void go(string &s, int l, int r, int k) {
		int len = (r - l + 1);
		k = k % len;
		for (int i = 0; i < k; i++) {
				char tm = s[r];
				for (int i = r; i > l; i--)
						s[i] = s[i - 1];

				s[l] = tm;
		}
}

int main() {
		string s;
		cin >> s;
		s = " " + s;
		int m;
		cin >> m;
		int l, r, k;
		while (m--) {
				cin >> l >> r >> k;
				go(s, l, r, k);
		}
		for (int i = 1; i < s.size(); i++)
				printf("%c", s[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

void go(string &s, int l, int r, int k) {
		int len = (r - l + 1);
		string s1 = s.substr(l, len);
		s1 = s1.substr(s1.size() - k, s1.size()) + s1.substr(0, s1.size() - k);
		for (int i = 0; i < k; i++) {
				s[l + i] = s1[i];
		}
		for (int i = k; i < len; i++)
				s[l + i] = s1[i];
}

int main() {
		string s;
		cin >> s;
		s = " " + s;
		int m;
		cin >> m;
		int l, r, k;
		while (m--) {
				cin >> l >> r >> k;
				go(s, l, r, k);
		}
		for (int i = 1; i < s.size(); i++)
				printf("%c", s[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

char s[10006];

void go(int l, int r, int k) {
		int len = (r - l + 1);
		k = k % len;
		for (int i = 0; i < k; i++) {
				char tm = s[r];
				for (int i = r; i > l; i--)
						s[i] = s[i - 1];

				s[l] = tm;
		}
}

int main() {
		scanf("%s", s + 1);
		int m;
		scanf("%d", &m);
		int l, r, k;
		while (m--) {
				scanf("%d %d %d", &l, &r, &k);
				go(l, r, k);
		}
		for (int i = 1; s[i] != '\n'; i++)
				printf("%c", s[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <string>
#include <sstream>
#include <iomanip>

#include <algorithm>
#include <list>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <bitset>

#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <memory.h>
#include <ctype.h>

using namespace std;

void go(string &s, int l, int r, int k) {
		int len = (r - l + 1);
		k = k % len;
		string s1 = s.substr(l, len);
		s1 = s1.substr(s1.size() - k, s1.size()) + s1.substr(0, s1.size() - k);
		for (int i = 0; i < k; i++) {
				s[l + i] = s1[i];
		}
		for (int i = k; i < len; i++)
				s[l + i] = s1[i];
}

int main() {
		string s;
		cin >> s;
		s = " " + s;
		int m;
		cin >> m;
		int l, r, k;
		while (m--) {
				cin >> l >> r >> k;
				go(s, l, r, k);
		}
		for (int i = 1; i < s.size(); i++)
				printf("%c", s[i]);
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	int m, l, r, k;
	getline(cin, s);
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r >> k;
		string sub=s.substr(l-1, r-l+1);
		for (int j = 0; j < k%(r-l+1); ++j)
		{
			char c = sub[r-l];
			for (int k = r-l; k > 0; --k)
				sub[k] = sub[k-1];
			sub[0] = c;
		}
		s.replace(l-1,r-l+1,sub);
	}
	cout << s;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	int m, l, r, k;
	getline(cin, s);
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r >> k;
		string sub=s.substr(l-1, r-l+1);
		for (int j = 0; j < k/(r-l+1); ++j)
		{
			char c = sub[r-l];
			for (int k = r-l; k > 0; --k)
				sub[k] = sub[k-1];
			sub[0] = c;
		}
		s.replace(l-1,r-l+1,sub);
	}
	cout << s;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	int m, l, r, k;
	getline(cin, s);
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r >> k;
		string sub=s.substr(l-1, r-l+1);
		for (int j = 0; j < k; ++j)
		{
			char c = sub[r-l];
			for (int k = r-l; k > 0; --k)
				sub[k] = sub[k-1];
			sub[0] = c;
		}
		s.replace(l-1,r-l+1,sub);
	}
	cout << s;
	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
	string s;
	int m, l, r, k;
	getline(cin, s);
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> l >> r >> k;
		k = k%(r-l+1);
		rotate(&s[l-1], &s[r-k], &s[r]);
	}
	cout << s;
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

char a[1010][1010];
int  answer[1010][1010];
int used[1010][1010];

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main()
{
	//freopen("alex.in", "r", stdin);
	//freopen("alex.out", "w", stdout);
	string str;
	cin >> str;
	cin >> k;
	int l, r, t;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r >> t;
		l--;
		r--;
		t %= (r - l + 1);
		int len = (r - l + 1);
		string re = str.substr(l, len);
		if (t == 0) continue;
		int ind = ((int)re.size()) - t;
		for (int j = l; j <= r; j++)
		{
			str[j] = re[ind];
			ind++;
			if (ind >= len)
			{
				ind = 0;
			}
		}

	}
	cout << str;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

char a[1010][1010];
int  answer[1010][1010];
int used[1010][1010];

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main()
{
	//freopen("alex.in", "r", stdin);
	//freopen("alex.out", "w", stdout);
	string str;
	cin >> str;
	cin >> k;
	int l, r, t;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r >> t;
		l--;
		r--;
		t %= (r - l + 1);
		int len = (r - l + 1);
		int ind = l + t;
		string re = str.substr(l, len);
		for (int j = l; j <= r; j++)
		{
			str[j] = re[ind];
			ind++;
			if (ind >= len)
			{
				ind = 0;
			}
		}

	}
	cout << str;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iostream>
#include <functional>
#include <time.h>
#include <cmath>
#include <deque>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define piii pair<int, pair<int, int> >
#define plll pair<ll, pair<ll, ll> >

ll EPS = 1000000007;
double PI = 3.14159265358979323846;
const int MAXN = 1000040;

ll abss(ll h) {
	return max(h, -h);
}

double fabss(double h) {
	return max(h, -h);
}

ll ceill(ll x, ll y) {
	if (x % y != 0) return (x / y) + 1;
	return x / y;
}

string itos(ll num) {
	string str = "";
	if (num == 0) return "0";
	while (num != 0) {
		str += ((num % 10) + '0');
		num /= 10;
	}
	reverse(str.begin(), str.end());
	return str;
}

ll sstoi(string num) {
	ll count = 1;
	for (int i = 0; i < (int)num.size() - 1; i++) {
		count *= 10;
	}
	ll ans = 0;
	for (int i = 0; i < (int)num.size(); i++) {
		ans += (num[i] - '0') * count;
		count /= 10;

	}
	return ans;
}

int n, m, k;

char a[1010][1010];
int  answer[1010][1010];
int used[1010][1010];

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main()
{
	//freopen("alex.in", "r", stdin);
	//freopen("alex.out", "w", stdout);
	string str;
	cin >> str;
	cin >> k;
	int l, r, t;
	for (int i = 0; i < k; i++)
	{
		cin >> l >> r >> t;
		l--;
		r--;
		t %= (r - l + 1);
		int len = (r - l + 1);
		string re = str.substr(l, len);
		int ind = (int)re.size() - t;
		for (int j = l; j <= r; j++)
		{
			str[j] = re[ind];
			ind++;
			if (ind >= len)
			{
				ind = 0;
			}
		}

	}
	cout << str;
}


#include <iostream>
#include <string>

using namespace std;

void shifter(string &input, long int l, long int r, long int k){

	char temp;
	l--;
	r--;
	for (long int i = 0; i < k; i++)
	{
		temp = input[r];

		for (long int j = 0; j < (r-l); j++)
		{
			input[r - j] = input[r - j - 1];
		}
		input[l] = temp;
	}

}

int main(){

	long int m , l , r , k;
	string input;

	cin >> input;
	cin >> m;

	for (int i = 0; i < m; i++)
	{
		cin >> l >> r >> k;
		shifter(input, l, r, k);

	}

	cout << input << endl;

	return 0;
}


#include <iostream>
#include <string>

using namespace std;

void shifter(string &input, long int l, long int r, long int k){

    string temp;
    l--;
    r--;
    k = k % (r - l + 1);

        temp = input.substr((r-k+1),r);

        for (long int j = 0; j < (r-l-k+1); j++)
        {
            input[r - j] = input[r - j - k];
        }
        for (long int t = 0; t < k; t++)
        {
            input[l + k - t-1] = temp[k-t-1];
        }

}

int main(){

    long int m , l , r , k;
    string input;

    cin >> input;
    cin >> m;

    for (int i = 0; i < m; i++)
    {
        cin >> l >> r >> k;
        shifter(input, l, r, k);

    }

    cout << input << endl;

    return 0;
}


#include<string>
#include<iostream>
using namespace std;

string str;
string temp;
int m;
int l, r, k;

void handle(){
    temp = str;
    int len = r - l + 1;
    k %= len;
    for (int i = l; i <= r; i++){
        int f = (i + k) % (r+1);
        if (f < l) f += l;
        str[f] = temp[i];
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    cin >> str;
    cin >> m;
    for (int i = 0; i < m; i++){
        cin >> l >> r >> k;
        l--, r--;
        handle();
    }
    cout << str;
}


#include<string>
#include<iostream>
using namespace std;

string str;
string temp;
int m;
int l, r, k;

void handle(){
	temp = str;
	int len = r - l + 1;
	k %= len;
	for (int i = 0; i < len; i++){
		int s, f;
		s = (l + i - 1) % r;
		if (s < l - 1) s += l - 1;
		f = (l + k - 1 + i) % r;
		if (f < l - 1) f += l - 1;
		str[f] = temp[s];
	}
}

int main(){
	//freopen("input.txt", "r", stdin);
	cin >> str;
	cin >> m;
	for (int i = 0; i < m; i++){
		cin >> l >> r >> k;
		handle();
	}
	cout << str;
}


#include<string>
#include<iostream>
using namespace std;

string str;
string temp;
int m;
int l, r, k;

void handle(){
    temp = str;
    int len = r - l + 1;
    k %= len;
    for (int i = l; i <= r; i++){
        int f = (i + k);
        if (f > r) f -= len;
        str[f] = temp[i];
    }
}

int main(){
    //freopen("input.txt", "r", stdin);
    cin >> str;
    cin >> m;
    for (int i = 0; i < m; i++){
        cin >> l >> r >> k;
        l--, r--;
        handle();
    }
    cout << str;
}


#include <iostream>
#include <cmath>
#include <list>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

#pragma warning (disable: 4996)

using namespace std;

int string2int(string s)
{
    int k = 1;
    int ans = 0;
    if (s == "")
        ans = -1;
    for (int i = s.size() - 1; i >= 0; i--, k *= 10)
    {
        int tmp = s[i] - '0';
        if (s[i] >= '0' && s[i] <= '9')
            ans += tmp*k;
        else
        {
            ans = -1;
            break;
        }
    }
    return ans;
}
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    while (b != 0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

int main()
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    getline(cin, s);
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        vector<char> a(r - l + 1);
        for (int j = l; j <= r; j++)
            if (j + k < r + 1)
                a[j + k - l] = s[j];
            else
                a[j + k - r - 1] = s[j];
        for (int j = l; j <= r; j++)
            s[j] = a[j - l];
    }

    cout << s;

    return 0;
}


#include <iostream>
#include <cmath>
#include <list>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

#pragma warning (disable: 4996)

using namespace std;

int string2int(string s)
{
    int k = 1;
    int ans = 0;
    if (s == "")
        ans = -1;
    for (int i = s.size() - 1; i >= 0; i--, k *= 10)
    {
        int tmp = s[i] - '0';
        if (s[i] >= '0' && s[i] <= '9')
            ans += tmp*k;
        else
        {
            ans = -1;
            break;
        }
    }
    return ans;
}
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    while (b != 0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

int main()
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    getline(cin, s);
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        k = k%s.size();
        vector<char> a(r - l + 1);
        for (int j = l; j <= r; j++)
            if (j + k - r <= 0)
                a[j + k - l] = s[j];
            else
                a[j + k - r - 1] = s[j];
        for (int j = l; j <= r; j++)
            s[j] = a[j - l];
    }
    cout << s;
    return 0;
}


#include <iostream>
#include <cmath>
#include <list>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

#pragma warning (disable: 4996)

using namespace std;

int string2int(string s)
{
    int k = 1;
    int ans = 0;
    if (s == "")
        ans = -1;
    for (int i = s.size() - 1; i >= 0; i--, k *= 10)
    {
        int tmp = s[i] - '0';
        if (s[i] >= '0' && s[i] <= '9')
            ans += tmp*k;
        else
        {
            ans = -1;
            break;
        }
    }
    return ans;
}
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    while (b != 0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

int main()
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    getline(cin, s);
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        vector<char> a(r - l + 1);
        for (int j = l; j <= r; j++)
            if (j + k - r <= 0)
                a[j + k - l] = s[j];
            else
                a[j + k - r - 1] = s[j];
        for (int j = l; j <= r; j++)
            s[j] = a[j - l];
    }
    cout << s;
    return 0;
}


#include <iostream>
#include <cmath>
#include <list>
#include <string>
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

#pragma warning (disable: 4996)

using namespace std;

int string2int(string s)
{
    int k = 1;
    int ans = 0;
    if (s == "")
        ans = -1;
    for (int i = s.size() - 1; i >= 0; i--, k *= 10)
    {
        int tmp = s[i] - '0';
        if (s[i] >= '0' && s[i] <= '9')
            ans += tmp*k;
        else
        {
            ans = -1;
            break;
        }
    }
    return ans;
}
int gcd(int a, int b)
{
    if (a < b)
        swap(a, b);
    while (b != 0)
    {
        int tmp = a;
        a = b;
        b = tmp%b;
    }
    return a;
}

int main()
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    getline(cin, s);
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int l, r, k;
        cin >> l >> r >> k;
        l--;
        r--;
        vector<char> a(r - l + 1);
        k = k%a.size();
        for (int j = l; j <= r; j++)
            if (j + k - r <= 0)
                a[j + k - l] = s[j];
            else
                a[j + k - r - 1] = s[j];
        for (int j = l; j <= r; j++)
            s[j] = a[j - l];
    }
    cout << s;
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <list>
#include <numeric>
using namespace std;
int main()
{
	string S;
	int n,l,r,k,i,size,t1,t2;
	cin>>S;
	cin>>n;
	size=S.length();
	reverse(S.begin(),S.end());
	for (i=0;i<n;i++)
	{
		cin>>l>>r>>k;
		t1=l;
		t2=r;
		l=size-t2;
		r=size-t1;
		k%=size;
		rotate(S.begin()+l,S.begin()+l+k,S.begin()+r+1);
	}
	reverse(S.begin(),S.end());
	cout<<S<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <list>
#include <numeric>
using namespace std;
int main()
{
	string S;
	int n,l,r,k,i,size,t1,t2;
	cin>>S;
	cin>>n;
	size=S.length();
	reverse(S.begin(),S.end());
	for (i=0;i<n;i++)
	{
		cin>>l>>r>>k;
		t1=l;
		t2=r;
		l=size-t2;
		r=size-t1;
		rotate(S.begin()+l,S.begin()+l+k,S.begin()+r+1);
	}
	reverse(S.begin(),S.end());
	cout<<S<<endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <list>
#include <numeric>
using namespace std;
int main()
{
	string S;
	int n,l,r,k,i,size,t1,t2;
	cin>>S;
	cin>>n;
	size=S.length();
	reverse(S.begin(),S.end());
	for (i=0;i<n;i++)
	{
		cin>>l>>r>>k;
		t1=l;
		t2=r;
		l=size-t2;
		r=size-t1;
		k%=(r-l+1);
		rotate(S.begin()+l,S.begin()+l+k,S.begin()+r+1);
	}
	reverse(S.begin(),S.end());
	cout<<S<<endl;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <utility>
#include <string>
#include <math.h>

using namespace std;

#define INF (int)1e9
#define MAX (int)1e6+1

int main()
{
	string str; int l, r, k,m;
	cin >> str >> m;
	while (m--)
	{
		scanf("%d %d %d", &l, &r, &k);	l--; r--;
		for (int j = 1; j <= k; j++)
		{
			char temp = str[r];
			for (int i = r; i >= l; i--)
			{
				if (i == l)
					str[i] = temp;
				else str[i] = str[i - 1];
			}
		}
	}
	cout << str;
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <stdio.h>
#include <stdlib.h>
#include <set>
#include <utility>
#include <string>
#include <math.h>

using namespace std;

#define INF (int)1e9
#define MAX (int)1e6+1

int main()
{
	string str,tstr; int l, r, k,m;
	cin >> str >> m; tstr=str;
	while (m--)
	{
		scanf("%d %d %d", &l, &r, &k);	l--; r--;
			for (int i = l;i<=r; i++)
                str[((i-l+k)%(r-l+1))+l]=tstr[i];
        tstr=str;
	}
	cout << str;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {
	if (k == 0) {
		return x;
	}
	else {
		char temp = x[r - 1];
		for (int j = r - 1; j >= l; j--){
			x[j] = x[j - 1];
		}
		x[l - 1] = temp;
		k--;
	}
	return query(x, l, r, k);
}
int main() {
	string x;
	long long int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		k %= (r - l + 1);
		if (k > 0)
			x = query(x, l, r, k);
	}

	cout << x << endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {
	if (k == 0) {
		return x;
	}
	else {
		char temp = x[r - 1];
		for (int j = r - 1; j >= l; j--){
			x[j] = x[j - 1];
		}
		x[l - 1] = temp;
		k--;
	}
	return query(x, l, r, k);
}
int main() {
	string x;
	int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		x = query(x ,l, r, k);
	}

	cout << x << endl;

	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {
	string a, b;
	a = x.substr(r - k, k);
	b = x.substr(l - 1, r - l + 1 - k);
	x.erase(r - k, k);
	x.erase(l - 1, r - l + 1 - k);
	x.insert(l - 1, b);
	x.insert(l - 1, a);
	return x;
}
int main() {
	string x;
	long long int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		k %= (r - l + 1);
		if (k > 0)
			x = query(x, l, r, k);
	}

	cout << x << endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {

	for (int i = 0; i < k; i++) {
		char temp = x[r - 1];
		for (int j = r - 1; j >= l; j--){
			x[j] = x[j-1];
		}
		x[l - 1] = temp;
	}
	return x;
}
int main() {
	string x;
	int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		x = query(x ,l, r, k);
	}

	cout << x << endl;

	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {
	if (k == 0) {
		return x;
	}
	else {
		char temp = x[r - 1];
		for (int j = r - 1; j >= l; j--){
			x[j] = x[j - 1];
		}
		x[l - 1] = temp;
		k--;
	}
	return query(x, l, r, k);
}
int main() {
	string x;
	int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		if (k > r - l + 1)
			k %= (r - l + 1);
		x = query(x, l, r, k);
	}

	cout << x << endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;

string query(string x, int l, int r, int k) {
	if (k == 0) {
		return x;
	}
	else {
		char temp = x[r - 1];
		for (int j = r - 1; j >= l; j--){
			x[j] = x[j - 1];
		}
		x[l - 1] = temp;
		k--;
	}
	return query(x, l, r, k);
}
int main() {
	string x;
	int m, l, r, k;
	cin >> x;
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> l >> r >> k;
		if (k >= r - l + 1)
			k = (r - l + 1) % k;
		x = query(x, l, r, k);
	}

	cout << x << endl;
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		//shiftCount %= input.size();
		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int mod(int a, int b)
{
	if (b < 0) //you can check for b == 0 separately and do what you want
		return mod(-a, -b);
	int ret = a % b;
	if (ret < 0)
		ret += b;
	return ret;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		shiftCount = mod(shiftCount, input.size());
		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int mod(int a, int b)
{
	if (b < 0) //you can check for b == 0 separately and do what you want
		return mod(-a, -b);
	int ret = a % b;
	if (ret < 0)
		ret += b;
	return ret;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		if (endIndex != startIndex && shiftCount > endIndex - startIndex)
		{
			shiftCount = shiftCount % (endIndex - startIndex);
		}

		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int mod(int a, int b)
{
	if (b < 0) //you can check for b == 0 separately and do what you want
		return mod(-a, -b);
	int ret = a % b;
	if (ret < 0)
		ret += b;
	return ret;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		if (shiftCount > endIndex - startIndex)
		{
			shiftCount = mod(shiftCount, endIndex - startIndex);
		}

		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		shiftCount %= input.size();
		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int mod(int a, int b)
{
	if (b < 0) //you can check for b == 0 separately and do what you want
		return mod(-a, -b);
	int ret = a % b;
	if (ret < 0)
		ret += b;
	return ret;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		shiftCount = mod(shiftCount, endIndex - startIndex);
		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#include <string>
#include <iostream>

template <typename T>
class Node
{
public:
	Node* Previous;
	Node* Next;
	const T& Value;

	Node(const T& value)
		: Value(value), Previous(nullptr), Next(nullptr)
	{
	}
};

Node<char>* NodifyString(const std::string& str)
{
	Node<char>* first = new Node<char>(str[0]);
	Node<char>* previous = first;
	for (int i = 1; i < str.size(); i++)
	{
		Node<char>* node = new Node<char>(str[i]);
		node->Previous = previous;
		if (previous != nullptr)
		{
			previous->Next = node;
		}

		previous = node;
	}

	return first;
}

Node<char>* GetXthNode(Node<char>* startNode, int x)
{
	for (int i = 0; i < x; i++) {
		if (startNode->Next == nullptr) {
			return nullptr;
		}

		startNode = startNode->Next;
	}

	return startNode;
}

Node<char>* Shift(Node<char>* node, int startIndex, int endIndex, int shiftCount)
{
	if (startIndex == endIndex) {
		return node;
	}

	Node<char>* firstNode = node;
	Node<char>* first = GetXthNode(node, startIndex);
	Node<char>* last = GetXthNode(first, endIndex - startIndex);

	for (int i = 0; i < shiftCount; i++) {
		Node<char>* oldFirst = first;
		Node<char>* newLast = last->Previous;
		Node<char>* newFirst = last;

		last->Previous = first->Previous;
		newLast->Next = last->Next;
		if (last->Next != nullptr) { last->Next->Previous = newLast; }
		last->Next = first;

		if (first->Previous == nullptr) {

			firstNode = last;
		}
		else {
			first->Previous->Next = last;
		}

		first->Previous = last;

		first = last;
		last = newLast;
	}

	return firstNode;
}

void PrintNodes(Node<char>* node)
{
	while (node != nullptr) {

			std::cout << node->Value;
		node = node->Next;
	}

	std::cout << std::endl;
}

int mod(int a, int b)
{
	if (b < 0) //you can check for b == 0 separately and do what you want
		return mod(-a, -b);
	int ret = a % b;
	if (ret < 0)
		ret += b;
	return ret;
}

int main()
{
	std::string input;
	std::cin >> input;

	Node<char>* node = NodifyString(input);
	int queryCount;
	std::cin >> queryCount;

	for (int i = 0; i < queryCount; i++)
	{
		int startIndex, endIndex, shiftCount;
		std::cin >> startIndex >> endIndex >> shiftCount;

		startIndex--;
		endIndex--;

		if (shiftCount > endIndex - startIndex)
		{
			shiftCount = shiftCount % (endIndex - startIndex);
		}

		node = Shift(node, startIndex, endIndex, shiftCount);

	}

	PrintNodes(node);
	std::cin.ignore(2);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define fo(i,x,y) for(int i=x; i<y; ++i)
#define of(i,x,y) for(int i=x; i>=y; --i)
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define mmii multimap<int,int>
#define mmll multimap<long long,long long>
#define mmsi multimap<string,int>
#define si set<int>
#define ll long long
#define sll set<long long>
#define ssi multiset<int>
#define sss multiset<string>
#define ssl multiset<long long>
#define sci(x) scanf("%i",&x);
#define scll(x) scanf("%I64d",&x);
#define scd(x) scanf("%d",&x);
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<math.h>
#include<deque>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<time.h>
#include<conio.h>
#include<queue>
using namespace std;
string s;
int m,l,r,k;
int main(){
	cin>>s>>m;
	fo(t,0,m){
		cin>>l>>r>>k;
		k%=(r-l+1);
		s = s.substr(0, l - 1) + s.substr(r - k , k) + s.substr(l - 1, r - l + 1 - k) + s.substr(r);
	}
	cout<<s;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define fo(i,x,y) for(int i=x; i<y; ++i)
#define of(i,x,y) for(int i=x; i>=y; --i)
#define mii map<int,int>
#define mll map<long long,long long>
#define msi map<string,int>
#define mmii multimap<int,int>
#define mmll multimap<long long,long long>
#define mmsi multimap<string,int>
#define si set<int>
#define ll long long
#define sll set<long long>
#define ssi multiset<int>
#define sss multiset<string>
#define ssl multiset<long long>
#define sci(x) scanf("%i",&x);
#define scll(x) scanf("%I64d",&x);
#define scd(x) scanf("%d",&x);
#include<stdio.h>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<math.h>
#include<deque>
#include<cmath>
#include<algorithm>
#include<string>
#include<string.h>
#include<time.h>
#include<conio.h>
#include<queue>
using namespace std;
string s;
int m,l,r,k;
int main(){
	cin>>s>>m;
	fo(t,0,m){
		cin>>l>>r>>k;
		k%=(r-l+1);
		fo(j,0,k){
			fo(i,l-1,r-1){
				swap(s[i],s[r-1]);
			}
		}
	}
	cout<<s;
	return 0;
}


#include <stdio.h>
#include <string.h>
int n, m;
int loc[10002]; // 지금 i번째 있는 녀석은 원래 어디였죠
char a[10002];
int l[30001];
int r[30001];
int k[30001];

void shiftgo(int left, int right, int num)
{
    int temp[10002];
    int i;
    num=num%(right-left+1);
    for(i=left ; i<=right ; i++)
    {
        temp[i]=loc[i];
    }
    for(i=left ; i<=left+num-1 ; i++)
    {
        loc[i]=temp[i-num+right-left+1];
    }
    for(i=left+num ; i<=right ; i++)
    {
        loc[i]=temp[i-num];
    }
}

int main(void)
{
    scanf("%s",&a[1]);
    int i;
    int n=strlen(&a[1]);
    for(i=1 ; i<=n ; i++)
    {
        loc[i]=i;
    }
    scanf("%d",&m);
    for(i=1 ; i<=m ; i++)
    {
        scanf("%d %d %d",&l[i],&r[i],&k[i]);
    }
    for(i=1 ; i<=m ; i++)
    {
        shiftgo(l[i],r[i],k[i]);
    }
    for(i=1 ; i<=n ; i++)
    {
        printf("%c",a[loc[i]]);
    }
    return 0;
}