Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
q = int(input())
flag = True
ans = s

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        ans.insert(0, query[2])
      else:
        ans.append(query[2])
    else:
      if flag:
        ans.append(query[2])
      else:
        ans.insert(0, query[2])

if flag:
  print("".join(ans))
else:
  t = ans[::-1]
  print("".join(t))

Fixed submission:
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s[::-1], h]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

flag = True
ans = s
for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        ans = query[2] + ans
      else:
        ans+=query[2]
    else:
      if flag:
        ans+=query[2]
      else:
        ans = query[2] + ans

if flag:
  for i in ans:
    print(i, end="")
else:
  t = ans[::-1]
  for i in t:
    print(i, end="")



Fixed submission:
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s[::-1], h]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

flag = True
ans = s
for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        ans = query[2] + ans
      else:
        ans+=query[2]
    else:
      if flag:
        ans+=query[2]
      else:
        ans = query[2] + ans

if flag:
  for i in ans:
    print(i, end="")
else:
  t = ans[::-1]
  for i in t:
    print(i, end="")



Fixed submission:
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s[::-1], h]))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

flag = True
ans = s
for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    flag = not flag
  else:
    if int(query[1]) == 1:
      if flag:
        ans = query[2] + ans
      else:
        ans+=query[2]
    else:
      if flag:
        ans+=query[2]
      else:
        ans = query[2] + ans

if flag:
  print("".join(ans))
else:
  t = ans[::-1]
  print("".join(t))



Fixed submission:
s = input()
q = int(input())
revFlag = False
head, tail = [], []

for i in range(q):
  query = list(input().split())
  if int(query[0]) == 1:
    revFlag = not revFlag
  else:
    if int(query[1]) == 1:
      if not revFlag:
        head.append(query[2])
      else:
        tail.append(query[2])
    else:
      if not revFlag:
        tail.append(query[2])
      else:
        head.append(query[2])

if not revFlag:
  h = "".join(reversed(head))
  t = "".join(tail)
  print("".join([h, s, t]))
else:
  h = "".join(head)
  t = "".join(reversed(tail))
  print("".join([t, s[::-1], h]))