Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S=input()
  N=int(input())
  cnt=0
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        S=tmp[2]+S
        
      else:
        S=S+tmp[2]
        
  if cnt%2!=0:
    S=''.join(list(reversed(S)))

  print(S)
if __name__=='__main__':
  main()
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S=input()
  N=int(input())
  cnt=0
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        new=tmp[2]+S
        S=new
      else:
        new=S+tmp[2]
        S=new
  if cnt%2!=0:
    S=''.join(list(reversed(S)))

  print(S)
if __name__=='__main__':
  main()
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S=input()
  N=int(input())
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      S=''.join(list(reversed(S)))
    else:
      if tmp[1]=='1':
        new=tmp[2]+S
        S=new
      else:
        new=S+tmp[2]
        S=new
  print(S)
if __name__=='__main__':
  main()
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S=input()
  N=int(input())
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      S=''.join(list(reversed(S)))
    else:
      if tmp[1]=='1':
        new=tmp[2]+S
        S=new
      else:
        new=S+tmp[2]
        S=new
  print(S)
if __name__=='__main__':
  main()
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  S=input()
  N=int(input())
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      S=S[::-1]
    else:
      if tmp[1]=='1':
        new=tmp[2]+S
        S=new
      else:
        new=S+tmp[2]
        S=new
  print(S)
if __name__=='__main__':
  main()
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
N=int(input())
Q=[]
for i in range(N):
  tmp=[i for i in input().split() ]
  if len(tmp)==1:
    S=S[::-1]
  else:
    if int(tmp[1])==1:
      new=tmp[2]+S
      S=new
    else:
      new=S+tmp[2]
      S=new
print(S)
   


Fixed submission:
def main():
  S=input()
  N=int(input())
  cnt=0
  f=''
  b=''
  for i in range(N):
    tmp=[i for i in input().split() ]
    if tmp[0]=='1':
      cnt+=1
    else:
      if (cnt+int(tmp[1]))%2==1:
        f=tmp[2]+f
        
      else:
        b=b+tmp[2]
  ans=f+S+b        
  if cnt%2!=0:
    ans=''.join(list(reversed(ans)))

  print(ans)
if __name__=='__main__':
  main()