๐ ๋ฌธ์  ์ฌ์ดํธ : https://www.acmicpc.net/problem/5430
์ด ๋ฌธ์ ๋ ๋ฐฐ์ด์์ popleft์ reverse๋ฅผ ์ฌ์ฉํด์ผํ๋ ๋ฌธ์ ์ด๋ค. ํ์ง๋ง, ๋ฌธ์ ์์ reverse๊ฐ ์ฃผ์ด์ง ๋๋ง๋ค ๋ฐฐ์ด์ reverse๋ฅผ ์ํํ๋ฉด ์๊ฐ ์ด๊ณผ๊ฐ ๋ฐ์ํ ๊ฒ์ด๋ค. ๋ฐ๋ผ์ reverse๊ฐ ์ ๋ ฅ๋๋ ๊ฒ์ ๋ณ์๋ก ์ ์ฅ๋ง ํด๋๊ธฐ๋ก ํ๊ณ , pop์ ํ ๋ reverse์ ๊ฐ์ ๋ฐ๋ผ popleft() ๋๋ pop()์ ์งํํ์๋ค. ๋ง์ง๋ง์ผ๋ก reverse๊ฐ ์ ๋ ฅ๋ ํ์๊ฐ ํ์์ด๋ฉด ๋ง์ง๋ง์ reverse๋ฅผ ํด์ฃผ๊ณ ๊ฒฐ๊ณผ ์ถ๋ ฅ์ ์งํํ์๋ค.
import sys
from collections import deque
t = int(input())
for _ in range(t):
    commands = sys.stdin.readline().rstrip()
    n = int(input())
    arr = sys.stdin.readline().rstrip()[1:-1].split(",")
    q = deque(arr)
    isTrue = True
    reverse = 0
    if n == 0:
        q = []
    
    for command in commands:
        if command == "R":
            reverse += 1
        elif command == "D":
            if len(q) == 0:
                isTrue = False
                break
            if reverse % 2 == 0:
                q.popleft()
            else:
                q.pop()
    if isTrue:
        if reverse % 2 == 0:
            print("[" + ",".join(q) + "]")
        else:
            q.reverse()
            print("[" + ",".join(q) + "]")
    else:
        print("error")