Buggy python submission (verdict: Runtime Error):
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    for s_ in s.reverse():
        print(s_, end='')

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Runtime Error):
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    else:
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    for s_ in s[::-1]:
        print(s_, end='')

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s = '{}{}'.format(strlist[4],s)
        else:
            s = '{}{}'.format(s,strlist[4])
    else:
        if r%2==0:
            s = '{}{}'.format(s,strlist[4])
        else:
            s = '{}{}'.format(strlist[4],s)
if r%2==0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
for i in range(n):
  strlist=input()
  if strlist[0]=='1':
    s=s[::-1]
  elif strlist[0]=='2' and strlist[2] == '1':
    s = '{}{}'.format(strlist[4],s)
  else:
    s = '{}{}'.format(s,strlist[4])
print(s)

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
for i in range(n):
  strlist=input()
  if strlist[0]=='1':
    s=s[::-1]
  elif strlist[0]=='2' and strlist[2] == '1':
    s = '{}{}'.format(strlist[4],s)
  elif strlist[0]=='2' and strlist[2] == '2':
    s = '{}{}'.format(s,strlist[4])
print(s)


Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
n=int(input())
strlist=[input() for i in range(n)]
for i in range(n):
  if strlist[i][0]=='1':
    s=s[::-1]
  elif strlist[i][0]=='2' and strlist[i][2] == '1':
    s = '{}{}'.format(strlist[i][4],s)
  elif strlist[i][0]=='2' and strlist[i][2] == '2':
    s = '{}{}'.format(s,strlist[i][4])
print(s)

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')

Buggy python submission (verdict: Runtime Error):
s=input()
n=int(input())
strlist=[input() for i in range(n)]
for i in range(n):
  if i==1:
    s=s[::-1]
  elif i==2 and strlist[i][2] == 1:
    s = '{}{}'.format(strlist[i][4],s)
  elif i==2 and strlist[i][2] == 2:
    s = '{}{}'.format(s,strlist[i][4])
print(s)

Fixed submission:
from collections import deque
s=deque(input())
n=int(input())
r=0
for i in range(n):
    strlist=input()
    if strlist[0]=='1':
        r+=1
    elif strlist[0]=='2' and strlist[2] == '1':
        if r%2==0:
            s.appendleft(strlist[4])
        else:
            s.append(strlist[4])
    elif strlist[0]=='2' and strlist[2] =='2':
        if r%2==0:
            s.append(strlist[4])
        else:
            s.appendleft(strlist[4])
if r%2==0:
    for s_ in s:
        print(s_, end='')
else:
    s.reverse()
    for s_ in s:
        print(s_, end='')