//还是未能成功
#include<iostream>
#include<stack>
//#include<queue>
#include<fstream>
using namespace std;
char book[105];
int count=0;
int input(int &count)
{
ifstream cin("g.in");
int m,n;
cin>>m>>n;
string cmd;
count=0;
stack<char>s;
// queue<char>q;
for(int j=0;j<n;j++)
{
cin>>book[j];
// s.push(book[i]);
// q.push(book[i]);
count++;
}
char bk1;int bk2;
for(int i=0;i<m;i++)
{
cin>>cmd;
if (cmd=="ADD")
{
count++;
cin>>bk1;
book[count]=bk1;
}
else if (cmd=="THROW")
{
cin>>bk2;
for(int j=bk2-1;j<count;j++)
{
book[j-bk2+1]=book[j];
}
count=count-bk2;
}
else if (cmd=="BREVERSE")
{
cin>>bk2;
for(int j=bk2-1;j<count;j++)
{
s.push(book[j]);
}
for(int j=bk2-1;j<count;j++)
{
book[j]=s.pop();
}
}
else if (cmd=="TREVERSE")
{
cin>>bk2;
for(int j=0;j<bk2;j++)
{
s.push(book[j]);
}
for(int j=0;j<bk2;j++)
{
book[j]=s.pop();
}
}
else if (cmd=="BRT")
{
cin>>bk2;
for(int j=bk2-1;j<count;j++)
{
s.push(book[j]);
}
for(int j=count-1;j>=bk2;j--)
{
book[j]=book[j-bk2];
}
for(int j=0;j<bk2;j++)
{
book[j]=s.pop();
}
}
else if (cmd=="TRB")
{
cin>>bk2;
for(int j=0;j<bk2;j++)
{
s.push(book[j]);
}
for(int j=0;j<count-bk2;j++)
{
book[j+bk2]=book[j];
}
for(int j=0;j<bk2;j++)
{
book[bk2+j]=s.pop();
}
}
}
return count;
}
void output(int &count)
{
cout<<count<<endl;
for(int i=0;i<count;i++)
{
cout<<book[i]<<endl;
}
}
int main()
{
input(count);
output(count);
return 0;
}
g.in:
6 2
A
B
ADD C
BREVERSE 2
TREVERSE 2
THROW 2
BRT 2
TRB 2