Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      s = str[4] + s
	    else:
	      s = s+ str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      s = s+ str[4]
	    else:
	      s = str[4] + s

if( flag % 2 == 1):
  s = s[::-1]

print s
sys.stdout.flush()


Fixed submission:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

prev_cmd = 0
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          prev_cmd += 1
        if( str[0] == '2'):
	  if( prev_cmd %2 == 1):
	    s = s[::-1]
	  prev_cmd = 0
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

if( prev_cmd %2 == 1):
  s = s[::-1]

print s
sys.stdout.flush()


Fixed submission:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

prev_cmd = 0
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
	  if( prev_cmd == 1):
            prev_cmd = 0
          else:
            prev_cmd = 1
        if( str[0] == '2'):
	  if( prev_cmd == 1):
	    s = s[::-1]
	  prev_cmd = 0
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

if( prev_cmd == 1):
  s = s[::-1]

print s
sys.stdout.flush()

Fixed submission:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()

Buggy python submission (verdict: Time Limit Exceeded):
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
		s = s[::-1]
        if( str[0] == '2'):
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

print s
sys.stdout.flush()


Fixed submission:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/python
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
		s = s[::-1]
        if( str[0] == '2'):
          if( str[2] == '1'):
	    s = str[4] + s
          if( str[2] == '2'):
	    s = s + str[4]

print s
sys.stdout.flush()


Fixed submission:
import sys

s = sys.stdin.readline().replace('\n','')
q = sys.stdin.readline().replace('\n','')
q = int(q)

flag = 0
prev=""
end=""
for i in range(0,q):
	str = sys.stdin.readline().replace('\n','')
        if( str[0] == '1'):
          flag += 1
        if( str[0] == '2'):
          if( str[2] == '1'):
	    if( flag % 2 == 0):
	      prev = str[4] + prev
	    else:
	      end = end + str[4]
          if( str[2] == '2'):
	    if( flag % 2 == 0):
	      end = end + str[4]
	    else:
	      prev = str[4] + prev

ss = prev + s + end
if( flag % 2 == 1):
  ss = ss[::-1]

print ss
sys.stdout.flush()