package BOJ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
/**
* BOJ 1406
* stack 이용하지 않으면 B,P 연산 시간복잡도 O(n)
* https://www.acmicpc.net/problem/1406
*/
public class Editor_1406 {
private static Stack<Character> left = new Stack<>();
private static Stack<Character> right = new Stack<>();
private static char[] input;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
input = br.readLine().toCharArray();
int cnt = Integer.parseInt(br.readLine());
for (int i = 0; i < input.length; i++) {
left.push(input[i]);
}
while(cnt-- > 0){
String[] commandAndElement = br.readLine().split("\\s");
doCommand(commandAndElement);
}
print();
}
private static void print() {
StringBuilder sb = new StringBuilder();
while(!left.isEmpty()){
right.push(left.pop());
}
while(!right.isEmpty()){
sb.append(right.pop());
}
System.out.println(sb.toString());
}
private static void doCommand(String[] commandAndElement){
String command = commandAndElement[0];
switch (command){
case "L":
if(!left.isEmpty()){
right.push(left.pop());
}
break;
case "D":
if(!right.isEmpty()){
left.push(right.pop());
}
break;
case "B":
if(!left.isEmpty())
left.pop();
break;
case "P":
String element = commandAndElement[1];
left.push(element.toCharArray()[0]);
break;
}
}
}