Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s = l[2] + s
    else:
      s = s + l[2]
  else:
    f *= -1


print(s if f == 1 else s[::-1])


Fixed submission:
from collections import deque
s = deque(input())
#s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    f *= -1

if f == -1:
  s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
n = int(input())
f = 0
for i in range(n):
  l = input().split()
  if l[0] == "2":
    if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
      s.insert(0,l[2])
    else:
      s.append(l[2])
  else:
    if f == 0:
      f = 1
    else:
      f = 0

print("".join(s) if f == 0 else "".join(s[::-1]))


Fixed submission:
from collections import deque
s = deque(input())
#s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    f *= -1

if f == -1:
  s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
f = 0
for i in range(n):
  l = input().replace(" ","")
  if l[0] == "2":
    if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
      s = l[2] + s
    else:
      s = s + l[2]
  else:
    if f == 0:
      f = 1
    else:
      f = 0

print(s if f == 0 else s[::-1])


Fixed submission:
from collections import deque
s = deque(input())
#s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    f *= -1

if f == -1:
  s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
f = 0
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    if (l[1] == "1" and f == 0) or (l[1] == "2" and f == 1):
      s = l[2] + s
    else:
      s = s + l[2]
  else:
    if f == 0:
      f = 1
    else:
      f = 0

print(s if f == 0 else s[::-1])


Fixed submission:
from collections import deque
s = deque(input())
#s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    f *= -1

if f == -1:
  s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    if l[1] == "1":
      s = l[2] + s
    else:
      s = s + l[2]
  else:
    s = s[::-1]
print(s)

Fixed submission:
from collections import deque
s = deque(input())
#s = input()
n = int(input())
f = 1
for i in range(n):
  l = list(map(str, input().split()))
  if l[0] == "2":
    tmp = int(l[1])*f
    if tmp == 1 or tmp == -2:
      s.appendleft(l[2])
    else:
      s.append(l[2])
  else:
    f *= -1

if f == -1:
  s.reverse()
print("".join(s))