Buggy python submission (verdict: Time Limit Exceeded):
import sys
# input = sys.stdin.readline
# print(s)
s = input()
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]

for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      s = c+s
    else:
      s = s+c

print(s[::inv])

Fixed submission:
s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))

Buggy python submission (verdict: Runtime Error):
import sys
s = sys.stdin.readlines()

s = s[0]
q = int(s[1]) #int(input())
inv = 1

for t in s[2:q]:
  # t = input()
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      s = c+s
    else:
      s = s+c

print(s[::inv])

Fixed submission:
s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))

Buggy python submission (verdict: Runtime Error):
import sys
s = sys.stdin.readlines()

s = s[0]
q = int(s[1]) #int(input())
inv = 1

for t in s[2:q+1]:
  # t = input()
  if t[0] == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      s = c+s
    else:
      s = s+c

print(s[::inv])

Fixed submission:
s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))

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

print(s[::inv])

Fixed submission:
s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))

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

print(s)


Fixed submission:
s = list(input())
q = int(input()) #int(input())
inv = 1
query = [input() for _ in range(q)]
bef = []
aft = []


for t in query:
  if t == '1':
    inv *= -1 #s = s[::-1]
  else:
    _, f, c = map(str, t.split())
    if (f =='1' and inv == 1) or (f =='2' and inv == -1):
      # s = c+s
      bef.append(c)
    else:
      # s = s+c
      aft.append(c)

bef.reverse()
bef.extend(s)
bef.extend(aft)

print(''.join(bef[::inv]))