Open SHyeonL opened 1 year ago
from sys import stdin
left = list(input())
right = []
for i in range(int(input())):
command = stdin.readline().split()
if command[0] == 'P':
left.append(command[1])
elif command[0] == 'L' and left:
right.append(left.pop())
elif command[0] == 'D' and right:
left.append(right.pop())
elif command[0] =='B' and left:
left.pop()
answer = left + right[::-1]
print(''.join(answer))