Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline


# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
    s = input().strip()
    q = int(input())
    flg = True
    for i in range(q):
        t = input_list_str()
        if len(t) == 1:
            n = t[0]
            flg = False if flg is True else True
        else:
            n, f, c = t
            c = str(c).strip()
            if f == '1':
                if flg:
                    s = c + s
                else:
                    s = s + c
            else:
                if flg:
                    s = s + c
                else:
                    s = c + s
    if flg is False:
        s = s[::-1]
    print(s)


def bi(num, a, b, x):
    print((a * num) + (b * len(str(b))))
    if (a * num) + (b * len(str(b))) <= x:
        return False
    return True

def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Fixed submission:
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) + reverse_count == 2:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  order = True
  for _ in range(n):
    q = list(input_list_str())
    if len(q) == 1:
      order = False if order else True
      continue
    t, f, c = q
    if int(f) == 1:
      if order:
        w = c + w
      else:
        w = w + c
    else:
      if order:
        w = w + c
      else:
        w = c + w
  if order is False:
    w = w[::-1]
  print(w)

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Fixed submission:
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) + reverse_count == 2:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s = input()
  n = int(input())
  
  reverse_count = 0
  pre_s = ''
  after_s = ''
  for _ in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count += 1
      s = s[::-1]
      continue
    q, f, c = t
    if int(f) == 1:
      pre_s += c
      s = c + s
    else:
      after_s += c
      s = s + c
  
  print(s)
  exit()
  a = pre_s + s + after_s
  if reverse_count % 2 != 0:
    a = a[::-1]
  print(a)
    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
from functools import reduce
main()

Fixed submission:
def main():
  w = input()
  s = collections.deque(w)
  n = int(input())
  
  reverse_count = 0
  for i in range(n):
    t = list(input_list_str())
    if len(t) == 1:
      reverse_count = 1 - reverse_count
      continue
    q, f, c = t
    if int(f) + reverse_count == 2:
      s.append(c)
    else:
      s.appendleft(c)
  if reverse_count == 1:
    s.reverse()
  print(''.join(s))

    
def input_list():
  return map(int, input().split())

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

import math
import fractions
import collections
from functools import reduce
main()