Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S = C + S
            else:
                S = S + C
        else:
            if F == "1":
                S = S + C
            else:
                S = C + S

if rev == -1:
    S = S[::-1]

print(S)


Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F == "1":
                S.append(C)
            else:
                S.appendleft(C)

if rev == -1:
    S = reversed(S)

print("".join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S = C + S
            else:
                S = S + C
        else:
            if F == "1":
                S = S + C
            else:
                S = C + S

if rev == -1:
    S = S[::-1]

print(S)


Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F == "1":
                S.append(C)
            else:
                S.appendleft(C)

if rev == -1:
    S = reversed(S)

print("".join(S))

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

n = 1
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1":
    n *= -1
  else:
    f = int(query[1])
    c = query[2]
    if f * n == 1 or f * n == -2:
      s = c + s
    else:
      s = s + c

if n == -1:
  s = s[::-1]
  
print(s)

Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F == "1":
                S.append(C)
            else:
                S.appendleft(C)

if rev == -1:
    S = reversed(S)

print("".join(S))

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:
    f = query[1]
    c = query[2]
    if f == "1":
      s = c + s
    else:
      s = s + c

print(s)

Fixed submission:
from collections import deque

S = list(input())
Q = int(input())

S = deque(S)
rev = 1
for _ in range(Q):
    query = input()
    if len(query) == 1:
        rev *= -1
    else:
        T, F, C = query.split()
        if rev == 1:
            if F == "1":
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if F == "1":
                S.append(C)
            else:
                S.appendleft(C)

if rev == -1:
    S = reversed(S)

print("".join(S))