# ========================
#       Information
# ========================

# Direct Link: https://www.hackerrank.com/challenges/py-collections-deque/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python

# ========================
#         Solution
# ========================

from collections import deque

D = deque()

for _ in range(int(input())):
    oper, val, *args = input().split() + ['']
    eval(f'D.{oper} ({val})')

print(*D)

356e48c36ea96fc22673bf4f68015d5b2f9f476b
<mask token>

<mask token>
for _ in range(int(input())):
    oper, val, *args = input().split() + ['']
    eval(f'D.{oper} ({val})')
print(*D)

<mask token>
D = deque()
for _ in range(int(input())):
    oper, val, *args = input().split() + ['']
    eval(f'D.{oper} ({val})')
print(*D)

from collections import deque
D = deque()
for _ in range(int(input())):
    oper, val, *args = input().split() + ['']
    eval(f'D.{oper} ({val})')
print(*D)

# ========================
#       Information
# ========================

# Direct Link: https://www.hackerrank.com/challenges/py-collections-deque/problem
# Difficulty: Easy
# Max Score: 20
# Language: Python

# ========================
#         Solution
# ========================

from collections import deque

D = deque()

for _ in range(int(input())):
    oper, val, *args = input().split() + ['']
    eval(f'D.{oper} ({val})')

print(*D)
