s,_,*q=open(0)

a='%s'

p=1

for q in q:

  try:

    q,f,c=q.split()

    if(f<'2')^p:a+=c

    else:a=c+a

  except:p^=1

print(((a%s[:-1])[::p or-1]))
S = str(eval(input()))

Q = int(eval(input()))



head = ""

tail = ""

main = S



status = 0



while Q:

  Q -= 1

  l = list(map(str,input().split()))

  if l[0] == "1":

    status = (status+1)%2

  else:

    letter = l[2]

    if l[1] == "1":

      if status == 0:

        head += letter

      else:

        tail += letter

    else:

      if status == 0:

        tail += letter

      else:

        head += letter



if status == 0:

  print((head[::-1]+main+tail))

else:

  print((tail[::-1]+main[::-1]+head))

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

S = str(eval(input()))
Q = int(eval(input()))
head = ""
tail = ""
main = S
status = 0
while Q:
    Q -= 1
    l = list(map(str, input().split()))
    if l[0] == "1":
        status = (status + 1) % 2
    else:
        letter = l[2]
        if l[1] == "1":
            if status == 0:
                head += letter
            else:
                tail += letter
        else:
            if status == 0:
                tail += letter
            else:
                head += letter
if status == 0:
    print((head[::-1] + main + tail))
else:
    print((tail[::-1] + main[::-1] + head))

-s, _, *q = open(0) -a = "%s" -p = 1 -for q in q: -    try: -        q, f, c = q.split() -        if (f < "2") ^ p: -            a += c +S = str(eval(input())) +Q = int(eval(input())) +head = "" +tail = "" +main = S +status = 0 +while Q: +    Q -= 1 +    l = list(map(str, input().split())) +    if l[0] == "1": +        status = (status + 1) % 2 +    else: +        letter = l[2] +        if l[1] == "1": +            if status == 0: +                head += letter +            else: +                tail += letter -            a = c + a -    except: -        p ^= 1 -print(((a % s[:-1])[:: p or -1])) +            if status == 0: +                tail += letter +            else: +                head += letter +if status == 0: +    print((head[::-1] + main + tail)) +else: +    print((tail[::-1] + main[::-1] + head))