Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

rev=1

sf=[]
sb=[]

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf.insert(0,n[2])
    else:
      sb.append(n[2])

s=''.join(sf)+s+''.join(sb)

if rev==1:
  print(s)
else:
  print(s[::-1])


Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input().split()
  x=[]
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      x.append(n[2])
      x.append(s)
      s=''.join(x)
#      s=n[2]+s
    else:
      x.append(s)
      x.append(n[2])
      s=''.join(x)
#      s=s+n[2]
if rev==1:
  print(s)
else:
  print(s[::-1])


Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      s=n[2]+s
    else:
      s=s+n[2]
if rev==1:
  print(s)
else:
  print(s[::-1])

Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input()
  if n[0:1]=="1":
    rev*=-1
  else:
    m=n.split()
    if (m[1]=="1" and rev==1) or (m[1]=="2" and rev==-1):
      s=m[2]+s
    else:
      s=s+m[2]
if rev==1:
  print(s)
else:
  print(s[::-1])


Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    rev*=-1
  else:
    m=n.split()
    x=[]
    if (m[1]=="1" and rev==1) or (m[1]=="2" and rev==-1):
      x.append(m[2])
      x.append(s)
      s=''.join(x)
#      s=m[2]+s
    else:
      x.append(s)
      x.append(m[2])
      s=''.join(x)
#      s=s+m[2]
if rev==1:
  print(s)
else:
  print(s[::-1])


Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Runtime Error):
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    rev*=-1
  else:
    m=n.split()
    x=[]
    if (m[1]=="1" and rev==1) or (m[1]=="2" and rev==-1):
    x.append(m[2])
    x.append(s)
      s=''.join(x)
#      s=m[2]+s
    else:
    x.append(s)
    x.append(m[2])
      s=''.join(x)
#      s=s+m[2]
if rev==1:
  print(s)
else:
  print(s[::-1])


Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    s = s[::-1]
  else:
    m=n.split()
    x=[]
    if m[1]=="1":
      x.append(m[2])
      x.append(s)
      s=''.join(x)
#      s=m[2]+s
    else:
      x.append(s)
      x.append(m[2])
      s=''.join(x)
#      s=s+m[2]
print(s)
      

Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    s = s[::-1]
  else:
    m=n.split()
    x=[]
    if m[1]=="1":
      x.append(m[2])
      x.append(s)
      s=''.join(x)
#      s=m[2]+s
    else:
      x.append(s)
      x.append(m[2])
      s=''.join(x)
#      s=s+m[2]
print(s)
      

Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])

Buggy python submission (verdict: Time Limit Exceeded):
s=input()
q=int(input())

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    s = s[::-1]
  else:
    m=n.split()
    if m[1]=="1":
      s=m[2]+s
    else:
      s=s+m[2]
print(s)
      

Fixed submission:
s=input()
q=int(input())

rev=1

sf=""
sb=s

for _ in range(0,q):
  n=input().split()
  if n[0]=="1":
    rev*=-1
  else:
    if (n[1]=="1" and rev==1) or (n[1]=="2" and rev==-1):
      sf+=n[2]
    else:
      sb+=n[2]

s=sf[::-1]+sb

if rev==1:
  print(s)
else:
  print(s[::-1])