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

Fixed submission:
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
s = list(s)
q = int(input())
f = 1
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    f *= -1
  else:
    if f == 1:
      if query[1] == '1':
        s.insert(0, query[2])
      else:
        s.append(query[2])
    else:
      if query[1] == '1':
        s.append(query[2])
      else:
        s.insert(0, query[2])
if f == -1:
  s = s[::-1]
ans = ''.join(s)
print(ans)

Fixed submission:
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
f = 1
for i in range(q):
  query = input()
  if query[0] == '1':
    f *= -1
  else:
    if f == 1:
      if query[2] == '1':
        s = query[4] + s
      else:
        s += query[4]
    else:
      if query[2] == '1':
        s += query[4]
      else:
        s = query[4] + s
if f == -1:
  s = s[::-1]
print(s)

Fixed submission:
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)

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

Fixed submission:
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)

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

Fixed submission:
s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)