Buggy python submission (verdict: Time Limit Exceeded):
S = input()
T = ""
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S += I[2]
    else:
      T += I[2]
if d == 0:
  for i in range(len(T)-1, -1, -1):
    print(T[i], end="")
  for s in S:
    print(s, end="")
else:
  for i in range(len(S)-1, -1, -1):
    print(S[i], end="")
  for t in T:
    print(t, end="")
print()

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S = S + I[2]
    else:
      S = I[2] + S
if d == 1:
  S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
f = 0
for i in range(Q):
  Query = input().split()
  if Query[0] == '1':
    f = 1 - f
  else:
    if int(Query[1]) - f == 1:
      S = Query[2] + S
    else:
      S = S + Query[2]
if f == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
f = 0
for i in range(Q):
  Query = input().split()
  if Query[0] == '1':
    f = 1 - f
  else:
    if int(Query[1]) - f == 1:
      S = Query[2] + S
    else:
      S = S + Query[2]
if f == 0:
  print(S)
else:
  print(S[::-1])

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str, input()))
Q = int(input())
f = 0
for i in range(Q):
  Query = input().split()
  if Query[0] == '1':
    f = 1 - f
  else:
    if int(Query[1]) - f == 1:
      S = [Query[2]] + S
    else:
      S = S + [Query[2]]
if f == 0:
  for i in S:
    print(i, end="")
else:
  for i in range(len(S)-1, -1, -1):
    print(S[i], end="")
print("")

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str, input()))
Q = int(input())
f = 0
for i in range(Q):
  Query = input().split()
  if Query[0] == '1':
    f = 1 - f
  else:
    if int(Query[1]) - f == 1:
      S = [Query[2]] + S
    else:
      S = S + [Query[2]]
if f == 1:
  S.reverse()
print(''.join(S))

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()

Buggy python submission (verdict: Time Limit Exceeded):
S = list(map(str, input()))
Q = int(input())
for i in range(Q):
  Query = input().split()
  if Query[0] == '1':
    S.reverse()
  else:
    if Query[1] == '1':
      S = [Query[2]] + S
    else:
      S = S + [Query[2]]
print(''.join(S))

Fixed submission:
from collections import deque
S = deque(input())
Q = int(input())
d = 0 # d=0:right, d=1:left
for i in range(Q):
  I = list(input().split())
  if I[0] == "1":
    d ^= 1
  else:
    if d + int(I[1]) == 2:
      S.append(I[2])
    else:
      S.appendleft(I[2])
if d == 1:
  S.reverse()
for s in S:
  print(s, end="")
print()