s=eval(input())

q=int(eval(input()))

head=''

foot=''



a=0

for i in range(q):

  t=eval(input())

  if t=='1':

    a=a^1

  else:

    t, f, c = list(map(str, t.split()))

    f=int(f)

    if (f^a)&1==0:

      foot+=c

    else:

      head=c+head

s=head+s+foot

if a==1:

  s=s[::-1]

print(s)
s=eval(input())

q=int(eval(input()))

head=''

foot=''



a=0

for i in range(q):

  t=eval(input())

  if t=='1':

    a=a^1

  else:

    t, f, c = list(map(str, t.split()))

    f=int(f)

    if (f^a)&1==0:

      foot+=c

    else:

      head+=c

s=head[::-1]+s+foot

if a==1:

  s=s[::-1]

print(s)
s = eval(input())
q = int(eval(input()))
head = ""
foot = ""
a = 0
for i in range(q):
    t = eval(input())
    if t == "1":
        a = a ^ 1
    else:
        t, f, c = list(map(str, t.split()))
        f = int(f)
        if (f ^ a) & 1 == 0:
            foot += c
        else:
            head = c + head
s = head + s + foot
if a == 1:
    s = s[::-1]
print(s)

s = eval(input())
q = int(eval(input()))
head = ""
foot = ""
a = 0
for i in range(q):
    t = eval(input())
    if t == "1":
        a = a ^ 1
    else:
        t, f, c = list(map(str, t.split()))
        f = int(f)
        if (f ^ a) & 1 == 0:
            foot += c
        else:
            head += c
s = head[::-1] + s + foot
if a == 1:
    s = s[::-1]
print(s)

-            head = c + head -s = head + s + foot +            head += c +s = head[::-1] + s + foot