#include <iostream>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <list>
using namespace std;
list<char> my_list;
auto iter = my_list.end();
int count = 0;
void Move_left()
{
if (iter != my_list.begin())
iter--;
}
void Move_right()
{
if (iter != my_list.end())
iter++;
}
void Delete()
{
if (iter == my_list.begin())
return;
iter = my_list.erase(--iter);
}
void Add(char _letter)
{
my_list.insert(iter, _letter);
}
int main()
{
string str;
char command = '\0', letter = '\0';
cin >> str;
my_list = list<char>(str.begin(), str.end());
iter = my_list.end();
int num = 0;
cin >> num;
while(num--)
{
cin >> command;
switch(command)
{
case 'L': Move_left(); break;
case 'D': Move_right(); break;
case 'B': Delete(); break;
case 'P':
cin >> letter;
Add(letter);
break;
}
}
for (const auto& item : my_list)
cout << item;
return 0;
}