s,_,*q=open(0)

a=['',s[:-1]]

p=1

for q in q:

  q,*f=q[::2]

  if q>'1':

    f,c=f

    a[(1if f<'2'else 0)^p]+=c

  else:p^=1

print((a[p^1][::-1]+a[p]))
s,_,*q=open(0)

a=['',s[:-1]]

p=1

for q in q:

  if q>'2':a[(q<'2 2')^p]+=q[-2]

  else:p^=1

print((a[p^1][::-1]+a[p]))
s, _, *q = open(0)
a = ["", s[:-1]]
p = 1
for q in q:
    q, *f = q[::2]
    if q > "1":
        f, c = f
        a[(1 if f < "2" else 0) ^ p] += c
    else:
        p ^= 1
print((a[p ^ 1][::-1] + a[p]))

s, _, *q = open(0)
a = ["", s[:-1]]
p = 1
for q in q:
    if q > "2":
        a[(q < "2 2") ^ p] += q[-2]
    else:
        p ^= 1
print((a[p ^ 1][::-1] + a[p]))

-    q, *f = q[::2] -    if q > "1": -        f, c = f -        a[(1 if f < "2" else 0) ^ p] += c +    if q > "2": +        a[(q < "2 2") ^ p] += q[-2]