Buggy python submission (verdict: Runtime Error):
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=s[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
          l=(a[2],s)
          s=''.join(l)
        else:
          l=(s,a[2])
          s=''.join(l)
      else:
        if a[1]=='1':
          l=(s,a[2])
          s=''.join(l)
        else:
          l=(a[2],s)
          s=''.join(l)
  if count%2==1:
    s=s[::-1]
  print(s)
if __name__=='__main__':
  main()


Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
          l=[a[2],s]
          s=''.join(l)
        else:
          l=[s,a[2]]
          s=''.join(l)
      else:
        if a[1]=='1':
          l=[s,a[2]]
          s=''.join(l)
        else:
          l=[a[2],s]
          s=''.join(l)
  if count%2==1:
    s=s[::-1]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  count=0
  for _ in [0]*q:
    a=input().split()
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
          s=a[2]+s if a[1]=='1' else s+a[2]
      else:
          s=s+a[2] if a[1]=='1' else a[2]+s
  if count%2==1:
    s=s[::-1]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
          s=a[2]+s
        else:
          s=s+a[2]
      else:
        if a[1]=='1':
          s=s+a[2]
        else:
          s=a[2]+s
  if count%2==1:
    s=s[::-1]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==1:
        s=s[::-1]
        count=0
      if a[1]=='1':
        s=a[2]+s
      else:
        s=s+a[2] 
  if count%2==1:
    s=s[::-1]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Runtime Error):
def main():
  s=input()
  q=int(input())
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      s=reversed(s)
    else:
      if a[1]=='1':
        s=a[2]+s
      else:
        s=s+a[2]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  s=input()
  q=int(input())
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      s=s[::-1]
    else:
      if a[1]=='1':
        s=a[2]+s
      else:
        s=s+a[2]
  print(s)
if __name__=='__main__':
  main()

Fixed submission:
def main():
  from collections import deque
  s=deque(input())
  q=int(input())
  count=0
  for _ in [0]*q:
    a=list(input().split())
    if len(a)==1:
      count+=1
    else:
      if count%2==0:
        if a[1]=='1':
           s.appendleft(a[2])
        else:
          s.append(a[2])
      else:
        if a[1]=='1':
          s.append(a[2])
        else:
          l=(a[2],s)
          s.appendleft(a[2])
  if count%2==1:
    s=list(s)[::-1]
  print(''.join(s))
if __name__=='__main__':
  main()