Takahashi has a string S consisting of lowercase English letters.
Starting with this string, he will produce a new one in the procedure given as follows.
The procedure consists of Q operations. In Operation i (1 \leq i \leq Q), an integer T_i is provided, which means the following:
 - If T_i = 1: reverse the string S.
 - If T_i = 2: An integer F_i and a lowercase English letter C_i are additionally provided.
 - If F_i = 1 : Add C_i to the beginning of the string S.
 - If F_i = 2 : Add C_i to the end of the string S.
Help Takahashi by finding the final string that results from the procedure.

-----Constraints-----
 - 1 \leq |S| \leq 10^5
 - S consists of lowercase English letters.
 - 1 \leq Q \leq 2 \times 10^5
 - T_i = 1 or 2.
 - F_i = 1 or 2, if provided.
 - C_i is a lowercase English letter, if provided.

-----Input-----
Input is given from Standard Input in the following format:
S
Q
Query_1
:
Query_Q

In the 3-rd through the (Q+2)-th lines, Query_i is one of the following:
1

which means T_i = 1, and:
2 F_i C_i

which means T_i = 2.

-----Output-----
Print the resulting string.

-----Sample Input-----
a
4
2 1 p
1
2 2 c
1

-----Sample Output-----
cpa

There will be Q = 4 operations. Initially, S is a.
 - Operation 1: Add p at the beginning of S. S becomes pa.
 - Operation 2: Reverse S. S becomes ap.
 - Operation 3: Add c at the end of S. S becomes apc.
 - Operation 4: Reverse S. S becomes cpa.
Thus, the resulting string is cpa.

Difficulty: interview

Starter code:

Solutions:
S = input()
Q = int(input())
bs = ''
fs = ''
hanten = 0
for i in range(Q):
    query = list(input().split())
    if query[0] == '1':
        hanten += 1
    else:
        if query[1] == '1':
            if hanten % 2 == 0:
                fs += query[2]
            else:
                bs += query[2]
        else:
            if hanten % 2 == 0:
                bs += query[2]
            else:
                fs += query[2]
if hanten % 2 == 0:
    print(fs[::-1]+S+bs)
else:
    print(bs[::-1]+S[::-1]+fs)

from collections import deque
S=deque(input())
Q=int(input())
rev=0
for _ in range(Q):
    q=input()
    if q=='1':
        rev=1-rev
    else:
        q1,f,c=q.split()
        if rev:
            if f=='1':
                S.append(c)
            else:
                S.appendleft(c)
        else:
            if f=='1':
                S.appendleft(c)
            else:
                S.append(c)
if rev:
    S.reverse()
print(''.join(S))

from collections import deque

s = deque(input())
q = int(input())
flag = True

for _ in range(q) :
    tfc = input().split()

    if tfc[0] == '1' :
        if flag == True :
            flag = False
        else :
            flag = True
    else :
        if flag == True :
            if tfc[1] == '1' :
                s.appendleft(tfc[2])
            else :
                s.append(tfc[2])
        else :
            if tfc[1] == '1' :
                s.append(tfc[2])
            else :
                s.appendleft(tfc[2])

if flag == True :
    print(''.join(s))
else :
    s.reverse()
    print(''.join(s))

def main():
    from collections import deque
    s = deque(input())
    q = int(input())

    flag = 0
    query = []

    for _ in range(q):
        temp = input().split()
        if len(temp) == 1:
            flag += 1
        else:
            query.append(temp + [flag%2])

    for q in query:
        if q[-1] == 0:
            if q[1] == "1":
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == "1":
                s.append(q[2])
            else:
                s.appendleft(q[2])

    if flag % 2 == 1:
        print(("".join(list(s)[::-1])))
    else:
        print(("".join(s)))

main()


from collections import deque
s = list(input())
q = int(input())

d = deque()
for i in s:
    d.append(i)

c = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        c *= -1
    else:
        if t[1] == '1':
            if c == 1:
                d.appendleft(t[2])
            else:
                d.append(t[2])
        else:
            if c == 1:
                d.append(t[2])
            else:
                d.appendleft(t[2])

print((''.join(list(d)[::c])))


from collections import deque
s = deque(input())
q = int(input())
query = [list(input().split()) for _ in range(q)]

reverse = 0# 3 or 0

for i in range(q):
    if int(query[i][0]) == 1:
        reverse = abs(reverse-3)
    else:
        if abs(int(query[i][1])-reverse) == 1:
            s.appendleft(query[i][2])
        else:
            s.append(query[i][2])

if reverse:
    s = list(s)[::-1]
else:
    s = list(s)

print((''.join(list(map(str,s)))))


S = input()
top = 0
end = len(S)-1
toright = True
N = int(input())
Q = [S[i] if i <= end else "" for i in range(end+1+N)]

for i in range(N):
  q = input().split()
  if q[0]=="1":
    toright = not toright
  else:
    if not(toright ^ (q[1]=="1")):
      Q[top-1]=q[2]
      top -= 1
    else:
      Q[end+1]=q[2]
      end += 1
ans = ""
#print(Q)
#print(toright)
for i in range(top, end+1):
  ans += Q[i]
if not toright:
  ans = ans[::-1]
print(ans)


from collections import deque
S=deque()
f=input
S.extend(list(f()))
F=1
 
for _ in range(int(f())):
 q=input()
 if q[0]=='1':F=1-F
 else:
   if int(q[2])+F==2:S.appendleft(q[4])
   else:S.append(q[4])
print(''.join(list(S) if F==1 else list(S)[::-1]))

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

ans = collections.deque(ns())
q = ni()
now = 0
for i in range(q):
    query = ns().split(' ')
    if query[0] == '1':
        now = 1 - now
    else:
        f, c = query[1], query[2]
        if f == '1':
            if now == 1:
                ans.append(c)
            else:
                ans.appendleft(c)
        else:
            if now != 1:
                ans.append(c)
            else:
                ans.appendleft(c)

if now == 1:
    for i in range(len(ans)):
        print(ans[-(i+1)], end="")
else:
    for i in range(len(ans)):
        print(ans[i], end="")
print()

from sys import stdin
from collections import deque


def input():
    return stdin.readline().strip()


S = list(input())
q = deque(S)
is_flipped = False
for _ in range(int(input())):
    q_t, *q_d = input().split()
    if q_t == "1":
        is_flipped = not is_flipped
    else:
        f, c = q_d
        if (not is_flipped and f == "1") or (is_flipped and f == "2"):
            q.appendleft(c)
        else:
            q.append(c)
ans = list(q)
print("".join(ans[::-1])) if is_flipped else print("".join(ans))


S = input()
N = int(input())
flg = 0
L = []
for i in range(N):
    e = input().split()
    if e[0] == '1':
        flg += 1
        flg = flg%2
    else:
        L.append(((flg+int(e[1]))%2, e[2]))

S = ''.join(list(reversed(S))) if flg else S
s1, s2 = '', ''
for f, v in L:
    if (flg+f)%2 == 1:
        s1 += v
    else:
        s2 += v

ans = ''.join(list(reversed(s1))) + S + s2
print(ans)

from collections import deque
S=deque()
f=input
S.extend(f())
F=1
 
for _ in range(int(f())):
 q=input()
 if q[0]=='1':F=1-F
 else:
   if int(q[2])+F==2:S.appendleft(q[4])
   else:S.append(q[4])
print(''.join([list(S)[::-1],S][F]))

# Referred to https://atcoder.jp/contests/abc158/submissions/17106264
from collections import deque 
s,j=deque(input()),False
for _ in range(int(input())):
  t=input().split()
  if t[0]=='1':
    j=not j
    continue
  if t[1]=='1':
    if j: s.append(t[2])
    else: s.appendleft(t[2])
  else:
    if j: s.appendleft(t[2])
    else: s.append(t[2])
if j: s.reverse()
print(*s,sep='')


S = input()
Q = int(input())

flg = True
T, U = "", ""
for i in range(Q):
    q = list(input().split())
    if len(q) == 1:
        flg = not flg
    else:
        if flg:
            if q[1] == "1":
                T = q[2] + T
            else:
                U = U + q[2]
        else:
            if q[1] == "1":
                U = U + q[2]
            else:
                T = q[2] + T

S = T + S + U
if not flg:
    S = S[::-1]

print(S)


from queue import deque
S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = deque(), deque()

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L.appendleft(Query[i][2])
      else: R.append(Query[i][2])
    else:
      if count % 2 == 0: R.append(Query[i][2])
      else: L.appendleft(Query[i][2])
L, R = "".join(L), "".join(R)
if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

s = input()
q = int(input())

head = ''
tail = ''
rev = False
for _ in range(q):
    ql = list(input().split())

    if ql[0] == '1':
        head, tail = tail, head
        if rev:
            rev = False
        else:
            rev = True
    else:
        if ql[1] == '1':
            head += ql[2]
        else:
            tail += ql[2]

if rev:
    ans = head[::-1] + s[::-1] + tail
else:
    ans = head[::-1] + s + tail

print(ans)

import os, sys, re, math

S = input()
Q = int(input())

direction = 1
prefix = ''
suffix = ''
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        direction = 2 if direction == 1 else 1
    else:
        if int(query[1]) ^ direction == 0:
            prefix = query[2] + prefix
        else:
            suffix = suffix + query[2]

S = prefix + S + suffix
if direction == 1:
    print(S)
else:
    print((S[::-1]))


from collections import deque
S = str(input());s = []
for i in range(len(S)):
  s.append(S[i])
s = deque(s)
Q = int(input())
eo = 0
for query in range(Q):
  temp = list(map(str,input().split()))
  if temp[0] == "1":
    eo += 1 #反転したということになる
  else:
    if temp[1] == "1":
      if eo%2 == 0:
        s.appendleft(temp[2])
      else:
        s.append(temp[2])
    else:
      if eo%2 == 0:
        s.append(temp[2])
      else:
        s.appendleft(temp[2])
#print(s)
s = list(s)
if eo%2 == 0:
  ans = "".join(s)
else:
  s = s[::-1]
  ans = "".join(s)
print(ans)

from collections import deque

S = input()
q = int(input())
Query = [list(map(str, input().split())) for _ in range(q)]

flg = True

D = deque(S)

for query in Query:
    if query[0] == "1":
        flg = not flg
    else:
        F, C = query[1], query[2]
        if (F == "1") and (flg is True):
            D.appendleft(C)
        elif (F == "1") and (flg is False):
            D.append(C)
        elif (F == "2") and (flg is True):
            D.append(C)
        elif (F == "2") and (flg is False):
            D.appendleft(C)

if flg:
    print("".join(D))
else:
    print("".join(list(reversed(D))))

from collections import deque
S=deque()
S.extend(list(input()))
F=True

for _ in range(int(input())):
 q=input().split()
 if q[0]=='1':F=not(F)
 else:
   c=q[2]
   if (q[1]=='1' and F) or (q[1]=='2' and not(F)):S.appendleft(c)
   else:S.append(c)
print(''.join(list(S)) if F else ''.join(list(S)[::-1]))

def main():
	S = list(input())
	T = []
	reverse = False
	n_q = int(input())
	for i in range(n_q):
		q = input().split(" ")
		if q[0] == "1":
			reverse = not reverse
		elif q[0] == "2":
			f = q[1]
			c = q[2]
			if (f == "1" and not reverse) or (f == "2" and reverse):
				T.append(c)
			elif (f == "1" and reverse) or (f == "2" and not reverse):
				S.append(c)
	if reverse:
		S.reverse()
		ans = S + T
	elif not reverse:
		T.reverse()
		ans = T + S
	print("".join(ans))

main()

from collections import deque
S=deque()
f=input
S.extend(list(f()))
F=1
 
for _ in range(int(f())):
 q=input()
 if q[0]=='1':F=1-F
 else:
   if int(q[2])+F==2:S.appendleft(q[4])
   else:S.append(q[4])
print(''.join(S if F==1 else list(S)[::-1]))

from collections import deque

s = input()
q = int(input())
a = 1
p = deque([s])
for _ in range(q):
    tfc = list(input().split())
    if tfc[0] == '1':
        a *= -1
    else:
        c = tfc[2]
        if tfc[1] == '1':
            if a == 1:
                p.appendleft(c)
            else:
                p.append(c)
        else:
            if a == 1:
                p.append(c)
            else:
                p.appendleft(c)
print((''.join(p) if a == 1 else ''.join(p)[::-1]))


def main():
    s = str(input())
    q = int(input())
    lst = [list(map(str, input().split())) for _ in range(q)]
    switch = 0  # 0が通常　1が前

    str_lst = [s]
    front_lst = []
    for i in range(q):

        if lst[i][0] == '1':
            switch = 1 - switch

        else:
            f = lst[i][1]
            c = lst[i][2]

            if f == '1':  # 先頭に追加

                if switch == 0:
                    front_lst.append(c)

                else:
                    str_lst.append(c)

            else:

                if switch == 0:
                    str_lst.append(c)

                else:
                    front_lst.append(c)

    front = ''.join(front_lst)
    front = front[::-1]
    after = ''.join(str_lst)
    answer = front + after

    if switch == 1:
        answer = answer[::-1]

    print(answer)


def __starting_point():
    main()

__starting_point()

def N():
    return int(input())
def L():
    return list(map(int,input().split()))
def NL(n):
    return [list(map(int,input().split())) for i in range(n)]
mod = pow(10,9)+7

#import numpy as np
import sys
import math
import collections

s = input()
n = N()
f = False
h = ''
t = ''
for i in range(n):
    q = input().split()
    if (len(q) == 1):
        f = not(f)
    else:
        if (f and q[1]=='1')or(not(f)and q[1]=='2'):
            t += q[2]
        else:
            h += q[2]
if f:
    ans = t[::-1] + s[::-1] + h
else:
    ans = h[::-1] + s + t
print(ans)


S=input()
top=''
Q=int(input())
t=0
for i in range(Q):
    strA=input().split()
    if strA[0]=='1':
        t=t+1
    else:
        if strA[1]=='1':
            if t%2==0:
                top=top+strA[2]
            else:
                S=S+strA[2]
        else:
            if t%2==0:
                S=S+strA[2]
            else:
                top=top+strA[2]

if t%2==0:
    S=top[::-1]+S
else:
    S=S[::-1]+top
print(S)


from collections import deque
S=deque()
S.extend(list(input()))
Q=int(input())
F=True

for _ in range(Q):
 q=input().split()
 if q[0]=='1':
   F=not(F)
 else:
   c=q[2]
   if (q[1]=='1' and F) or (q[1]=='2' and not(F)):
       S.appendleft(c)
   else:
       S.append(c)
print(''.join(list(S)) if F else ''.join(list(S)[::-1]))


from collections import deque


def main():
    s = deque(input())
    q = int(input())
    flg = 0

    for i in range(q):
        l = list(map(str, input().split()))
        if len(l) == 1:
            flg = 1 - flg
        elif (flg == 0 and l[1] == "1") or (flg == 1 and l[1] == "2"):
            s.appendleft(l[2])
        else:
            s.append(l[2])

    if flg == 0:
        print(("".join(s)))
    else:
        print(("".join(reversed(s))))


main()


import sys
input = sys.stdin.readline # for speed up
#sys.setrecursionlimit(10**9)

s=list(input().replace("\n",""))

from collections import deque
dqn=deque(s)

n=int(input())
temp_rev=False
for _ in range(n):
	qfc=input().split()
	q=qfc[0]
	if q=="1":
		temp_rev=not temp_rev
	else: # q=="2"
	    f=qfc[1]
	    c=qfc[2]
	    if f=="1":
	        if temp_rev:
	            dqn.append(c)
	        else: # if not temp_rev:
	            dqn.appendleft(c)
	    else: # f=="2"
	        if temp_rev:
	            dqn.appendleft(c)
	        else: # if not temp_rev:
	            dqn.append(c)
	#print(temp_rev,dqn)
dqn=list(dqn)
#print(dqn)
if temp_rev:
	print(("".join([dqn[len(dqn)-1-ii] for ii in range(len(dqn))])))
else:
	print(("".join(dqn)))


def resolve():
    s = input()
    query = int(input())
    r = 0
    left = ''
    for i in range(query):
        q = input()
        if q[0]=='2':
            _,f,c = q.split()
            if (int(f)+r)%2 == 0:
                s += c
            else:
                left += c
        else:
            r = (r+1)%2
    print(left[::-1]+s if r==0 else s[::-1]+left)
resolve()

from collections import deque
s = deque(list(input()))
q = int(input())
top = 0
for i in range(q):
    t = input()
    if t[0] == "1":
        top = 1-top
        continue
    t = t.split()
    if t[1] == "1":
        if top == 0:
            s.appendleft(t[2])
        else:
            s.append(t[2])
    else:
        if top == 0:
            s.append(t[2])
        else:
            s.appendleft(t[2])
if top == 0:
    for i in range(len(s)):
        print(s[i],end="")
else:
    for i in range(len(s)-1, -1, -1):
        print(s[i],end="")

from collections import deque

poe=deque([])
S=input()
for i in range(len(S)):
    poe.append(S[i])
Q=int(input())
P=[]
cnt=0
for i in range(Q):
    a=list(input().split())
    P.append(a)

for i in range(Q):
    if len(P[i])==1:
        cnt+=1
    else:
        P[i][1]=int(P[i][1])+cnt
        if P[i][1]%2==1:
            poe.appendleft(P[i][2])
        else:
            poe.append(P[i][2])

poe=list(poe)
if cnt%2==1:
    poe=poe[::-1]
print(''.join(poe))

from collections import deque
S=deque()
S.extend(list(input()))
F=True

for _ in range(int(input())):
 p,*q=input().split()
 if p=='1':F=not(F)
 else:
   c=q[1]
   if (q[0]=='1' and F) or (q[0]=='2' and not(F)):S.appendleft(c)
   else:S.append(c)
print(''.join(list(S) if F else list(S)[::-1]))

from collections import deque

s = deque(input())
q = int(input())

flag = True
for _ in range(q):
    temp = input().split()
    if len(temp) == 1:
        flag = not flag
    else:
        if flag:
            if temp[1] == "1":
                s.appendleft(temp[2])
            else:
                s.append(temp[2])
        else:
            if temp[1] == "1":
                s.append(temp[2])
            else:
                s.appendleft(temp[2])

if flag:
    print("".join(s))
else:
    print("".join(list(s)[::-1]))

def main():
    S = input()
    Q = int(input())
    order = [list(input().split()) for _ in range(Q)]
    left_flag = 0
    right_flag = 0
    cnt = 0
    for i in range(Q):
        if order[i][0] == '1':
            cnt += 1
        else:
            if cnt%2 == 0:
                if order[i][1] == '1':
                    if left_flag == 1:
                        left = order[i][2] + left
                    else:
                        left = order[i][2]
                        left_flag = 1
                else:
                    if right_flag == 1:
                        right = right + order[i][2]
                    else:
                        right = order[i][2]
                        right_flag = 1
            else:
                if order[i][1] == '2':
                    if left_flag == 1:
                        left = order[i][2] + left
                    else:
                        left = order[i][2]
                        left_flag = 1
                else:
                    if right_flag == 1:
                        right = right + order[i][2]
                    else:
                        right = order[i][2]
                        right_flag = 1
    if left_flag == 1 and right_flag == 1:
        S = left + S + right
    elif left_flag == 1 and right_flag == 0:
        S = left + S
    elif left_flag == 0 and right_flag == 1:
        S = S + right
    else:
        S = S

    if cnt%2 == 0:
        return(S)
    else:
        S2 = S[-1]
        for i in range(len(S)-2,-1,-1):
            S2 = S2 + S[i]
        return S2

print((main()))


from collections import deque

S = list(input())
Q = int(input())
answer = deque(S)
reverse = False
for _ in range(Q):
  query = input()
  if query == '1':
    reverse ^= True
  else:
    ope, types, alphabet = query.split()
    if types == '1':
      if reverse:
        answer.append(alphabet)
      else:
        answer.appendleft(alphabet)
    else:
      if reverse:
        answer.appendleft(alphabet)
      else:
        answer.append(alphabet)
if reverse:
  result = ''
  for i in range(len(answer)):
    result += answer.pop()
  print(result)
else:
  result = ''
  for i in range(len(answer)):
    result += answer.popleft()
  print(result)


S = input()
Q = int(input())
T = 0
s = ""
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        T = (T+1) % 2
    elif (T == 0 and q[1] == "1") or (T == 1 and q[1] == "2"):
        s += q[2]
    else:
        S += q[2]
if T == 0:
    S = s[::-1] + S
    print(S)
else:
    S = S[::-1] + s
    print(S)

#!/usr/bin/env python3

#import
#import math
#import numpy as np

s = input()
q = int(input())

inv = False

fro = ""
end = ""

for _ in range(q):
    query = list(map(str, input().split()))

    if query[0] == "1":
        inv = not inv

    else:
        t = int(query[1])
        instr = query[2]
        if not inv:
            if t == 1:
                fro = instr + fro
            else:
                end = end + instr

        else:
            if t == 1:
                end = end + instr[::-1]
            else:
                fro = instr[::-1] + fro

ans = fro + s + end

if not inv:
    print(ans)

else:
    print((ans[::-1]))


from collections import deque
s = input()
q = int(input())
inv = False
pr, su = deque(), deque()
for _ in range(q):
    query = input()
    if query[0] == '1':
        inv = not inv
    else:
        _, f, c = query.split()
        if inv:
            if f == '1': su.append(c)
            else: pr.append(c)
        else:
            if f == '1': pr.append(c)
            else: su.append(c)
ans = ''.join(pr)[::-1] + s + ''.join(su)
print(ans[::-1] if inv else ans)

# -*- coding: utf-8 -*-
"""
Created on Tue Sep  8 14:42:59 2020

@author: liang
"""

from collections import deque
S = deque(input())
Q = int(input())

reverse = False

for i in range(Q):
    t = input().split()
    if int(t[0]) == 1:
        if reverse == False:
            reverse = True
        else:
            reverse = False
    else:
        F = int(t[1])
        C = t[2]
        if F == 1:
            if reverse == False:
                S.appendleft(C)
            else:
                S.append(C)
        else:
            if reverse == False:
                S.append(C)
            else:
                S.appendleft(C)

                
if reverse == False:
    print((''.join(S)))
else:
    print((''.join(reversed(S))))


import collections
S = list(input())
deq = collections.deque(S)
Q = int(input())
mode = 1
for i in range(Q):
    f = input()
    f1 = f[0]
    if f1 == '1':
        mode = mode*(-1)
    else:
        f1,F,C = map(str,f.split())
        if (F == '1' and mode == 1) or (F == '2' and mode == -1):
            deq.appendleft(C)
        if (F == '2' and mode == 1) or (F == '1' and mode == -1):
            deq.append(C)
if mode == -1:
    deq.reverse()
ans = ''.join(deq)
print(ans)

#!/usr/bin/env python3

#import
#import math
#import numpy as np

s = input()
q = int(input())

inv = False

fro = ""
end = ""

for _ in range(q):
    query = list(map(str, input().split()))

    if query[0] == "1":
        inv = not inv

    else:
        t = int(query[1])
        instr = query[2]
        if not inv:
            if t == 1:
                fro = instr + fro
            else:
                end = end + instr

        else:
            if t == 1:
                end = end + instr[::-1]
            else:
                fro = instr[::-1] + fro

ans = fro + s + end

if not inv:
    print(ans)

else:
    print(ans[::-1])

s=list(input())
from _collections import deque
s=deque(s)
q=int(input())
rev=False
for i in range(q):
    query=input()
    if len(query)==1:
        rev=not rev
    else:
        x,f,c=query.split()
        if f=="1":
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
n=len(s)

if rev:
    ans=[s[n-1-i] for i in range(n)]
else:
    ans=[s[i] for i in range(n)]
print("".join(ans))

from collections import deque 
s,j=deque(input()),False
for _ in range(int(input())):
  t=input().split()
  if t[0]=='1':
    j=not j
    continue
  if t[1]=='1':
    if j: s.append(t[2])
    else: s.appendleft(t[2])
  else:
    if j: s.appendleft(t[2])
    else: s.append(t[2])
if j: s.reverse()
print(*s,sep='')

from collections import deque
s = deque(input())
q = int(input())

flag = 0
for _ in range(q):
  query = list(map(str, input().split()))
  if query[0] == "1": flag = 1 - flag
  else:
    if query[1] == "1":
      if flag == 0: s.appendleft(query[2])
      else: s.append(query[2])
    else:
      if flag == 0: s.append(query[2])
      else: s.appendleft(query[2])

if flag == 1: s.reverse()
print(*s, sep="")

from collections import deque
s=deque(list(input()))
q=int(input())
count=0
for i in range(q):
    query=input()
    if query=="1":
        count+=1
    elif query[2]=="1":
        if count%2==0:
            s.appendleft(query[-1])
        else:
            s.append(query[-1])
    else:
        if count%2==0:
            s.append(query[-1])
        else:
            s.appendleft(query[-1])
if count%2==1:
    s.reverse()
print(*s,sep="")

from collections import deque
S = deque(list(input()))
q = int(input())
flag = False
for i in range(q):
  query = list(map(str,input().split()))
  if query[0] == "1" and flag == False:
    flag = True
  elif query[0] == "1" and flag == True:
    flag = False
  else:
    if (flag == False and query[1] == "1") or (flag == True and query[1] == "2"):
      S.appendleft(query[2])
    else:
      S.append(query[2])
if flag:
  S = list(S)[::-1]
else:
  S = list(S)
print("".join(map(str,list(S))))

from collections import deque
S = deque(input())
n = int(input())
Q = [list(map(str, input().split())) for _ in range(n)]

flg = True
for q in Q:
    if q[0] == "1":
        flg = not flg
    else:
        F = int(q[1])
        if not flg:
            F = 3 - F
        if F == 1:
            S.appendleft(q[2])
        if F == 2:
            S.append(q[2])

if not flg:
    S.reverse()
print("".join(S))

from collections import deque
import sys
input = sys.stdin.readline

Ss = input().rstrip()
Q = int(input())

isRev = False
queue = deque(Ss)
for _ in range(Q):
    ts = input().rstrip()
    if ts[0] == '1':
        isRev = not isRev
    else:
        tp, f, c = ts.split()
        if f == '1':
            if isRev:
                queue.append(c)
            else:
                queue.appendleft(c)
        else:
            if isRev:
                queue.appendleft(c)
            else:
                queue.append(c)

anss = list(queue)
if isRev:
    anss.reverse()

print((''.join(anss)))


from collections import deque

S = deque(list(input()))
Q = int(input())
flag = 0
for _ in range(Q):
    q = input()
    if q[0] == '1':
        flag = 1 - flag
    else:
        _, F, C = q.split()
        if int(F) - flag == 1:
            S.appendleft(C)
        else:
            S.append(C)
if flag:
    S.reverse()
print(''.join(S))

S = input()
Q = int(input())
query = [input().split() for _ in range(Q)]

switch = 1
top = []
bottom = []

for i in range(Q):
  if query[i][0] == "1":
    switch *= -1

  else:
    f = query[i][1]
    c = query[i][2]
    if switch == 1:
      if f == "1":
        top.append(c)
      else:
        bottom.append(c)
    else:
      if f == "1":
        bottom.append(c)
      else:
        top.append(c)

if switch == 1:
  ans = top[::-1] + list(S) + bottom
else:
  ans = bottom[::-1] + list(S)[::-1] + top
  
print("".join(ans))

# D - String Formation
from collections import deque 
S = deque(input())
Q = int(input())
Query = [list(input().split()) for _ in range(Q)]

# 文字列の向き (0: 正, 1: 逆)
rev = 0
for Q in Query:
    if Q[0] == '1':
        if rev == 0:
            rev = 1
        else:
            rev = 0
        continue
    if Q[1] == '1':
        if rev == 0:
            S.appendleft(Q[2])
        else:
            S.append(Q[2])
    else:
        if rev == 0:
            S.append(Q[2])
        else:
            S.appendleft(Q[2])

if rev == 1:
    ans = list(reversed(list(S)))
else:
    ans = list(S)
print(''.join(ans))

from collections import deque
S = input()
Q = int(input())
cnt = 0
D = deque()
D.append(S)
for _ in range(Q):
    q = input()
    if q == "1":
        cnt += 1
    else:
        q, f, c = list(map(str, q.split()))
        f = int(f)
        if cnt % 2 == 0:
            if f == 2:
                D.append(c)
            else:
                D.appendleft(c)
        else:
            if f == 2:
                D.appendleft(c)
            else:
                D.append(c)

X = "".join(D)

print((X if cnt % 2 == 0 else X[::-1]))


from collections import deque
s = deque(list(input()))
n = int(input())
normal = 0
for i in range(n):
  li = input().split()
  if int(li[0]) == 1:
    normal ^= 1
  else:
    k = int(li[1]) - 1
    k ^= normal
    if k == 1:
      s.append(li[2])
    else:
      s.appendleft(li[2])
print(''.join(s) if normal == 0 else ''.join(list(s)[::-1]))      

from collections import deque


Q=deque(list(input()))

q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return list(map(int,input().split()))
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

s = deque(X())
n = k()
normal = 0
for i in range(n):
  a = input().split()
  if int(a[0]) == 1:
    normal ^= 1
  else:
    k = int(a[1]) - 1
    k ^= normal
    if k == 1:
      s.append(a[2])
    else:
      s.appendleft(a[2])
print((''.join(s) if normal == 0 else ''.join(list(s)[::-1])))      


import sys
pin=sys.stdin.readline

S=pin()[:-1]
Q=int(pin())
now=1
ans1=""
ans2=""
for i in range(Q):
  D=pin().split()
  T=0
  F=0
  C=""
  if len(D)==1:
    T=int(D[0])
  else:
    T=int(D[0])
    F=int(D[1])
    C=D[2]
  if T==1:
    now*=-1
  else:
    if F==1:
      if now==1:
        ans1=C+ans1
      else:
        ans2=ans2+C
    else:
      if now==1:
        ans2=ans2+C
      else:
        ans1=C+ans1
if now==1:
  print((ans1+S+ans2))
else:
  print((ans2[::-1]+S[::-1]+ans1[::-1]))



s = input()
q = int(input())
rev = False
top = ''
for i in range(q):
  query = input().split()
  
  if query[0] == '1':
    rev = not rev
  else:
    
   
    if query[1] == '1':
      if rev: 
        s += query[2]
      else:
        top += query[2]
    elif query[1] == '2':
      if rev:
        top += query[2]
      else:
        s += query[2]
if rev:
  s = s[::-1] + top
else:
  s = top[::-1] + s
print(s)

from collections import deque
d = deque()
S = input()
d.append(S)
Q = int(input())
query = [list(input().split()) for _ in range(Q)]

rev = 0
for i in range(Q):
	if query[i][0] == str(1):
		rev += 1
	else:
		if rev % 2 == 0:
			if query[i][1] == str(1):
				d.appendleft(query[i][2])
			else:
				d.append(query[i][2])
		else:
			if query[i][1] == str(1):
				d.append(query[i][2])
			else:
				d.appendleft(query[i][2])

ans = ''.join(list(d))
if rev % 2 != 0:
	ans = ans[::-1]

print(ans)


from collections import deque
s=deque(list(input()))
n=int(input())
Q=[]
for i in range(n) :
    Q.append(list(input().split()))
 
count=0
for q in Q :
    if q[0]=="1" :
        count+=1
    elif q[0]=="2" and count%2==0 :
        if q[1]=="1" :
            s.appendleft(q[2])
        else :
            s.append(q[2])
    else :
        if q[1]=="1" :
            s.append(q[2])
        else :
            s.appendleft(q[2])
 
ans="".join(s)
if count%2==0 :
    print(ans)
else :
    print(ans[::-1])

s=input()
q=int(input())
que=[list(map(str,input().split())) for i in range(q)]
count=0
for i in que:
  if i[0]=="1":
    count+=1
ans=[[],[]]
ak=count
for i in que:
  if i[0]=="1":
    count-=1
  else:
    if i[1]=="1":
      ans[count%2].append(i[2])
    else:
      ans[(count+1)%2].append(i[2])
if ak%2==0:
  print("".join(reversed(ans[0]))+s+"".join(ans[1]))
else:
  print("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1]))

from collections import deque
d = deque(input())
n = int(input())
p=[]
flg = 0
for i in range(n):
  p = list(input().split())
  #print(p)
  if p[0] == "1":
    flg ^= 1 # flg == 1 の場合は左右反転
    #print(flg)
  else:    
    if p[1] == "1": # 1の場合は先頭
      if flg == 1: # 1の場合は反転
        d.append(p[2])
      else:
        d.appendleft(p[2]) # 左から入れる
    else:
      if flg == 1:
        d.appendleft(p[2]) # 左から入れる
      else:
        d.append(p[2])
  
if flg == 1:
  d.reverse()
a =""
for i in d:
  a += i
print(a)

from collections import deque
S=deque(input())
Q=int(input())
 
s=1
for i in range(Q):
  A = list(map(str,input().split()))
  if A[0]=='1':s*=-1;continue
  if A[1]=='1' and s==1:S.appendleft(A[2])
  elif A[1]=='2' and s==-1:S.appendleft(A[2])
  else:S.append(A[2])
  
if s==-1:S.reverse()
print(''.join(S))

s = input()
n = int(input())
d = 1
left = ""
right = ""

for i in range(n):
    q = input()
    
    if q == "1":
        d *= -1
        
    else:
        _,f,c = q.split()
        
        if d == 1:
            if f == "1":
                left += c
                
            else:
                right += c
                
        else:
            if f == "2":
                left += c
                
            else:
                right += c

ans = left[::-1] + s + right

print(ans[::d])

from collections import deque
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
input = sys.stdin.readline
S = list(input().rstrip())
S = deque(S)
input()
rev = 0
for line in readlines():
    q, *query, = line.split()
    if q == '1':
        rev ^= 1
    else:
        f, c = query
        if f == '1':
            if not rev:
                S.appendleft(c)
            else:
                S.append(c)
        else:
            if not rev:
                S.append(c)
            else:
                S.appendleft(c)

print((''.join(S) if not rev else ''.join(S)[::-1]))


S = input()
Q = int(input())
pre = ''#逆順
suf = ''
rev = 0
for i in range(Q):
    inp = input()
    if inp == '1':
        pre, suf = suf, pre
        rev += 1
    else:
        inp_l = inp.split()
        if inp_l[1] == '1':
            pre = pre + inp_l[2]
        else:
            suf = suf + inp_l[2]
if rev%2 == 0:
    print(''.join(list(reversed(pre)))+S+suf)
else:
    print(''.join(list(reversed(pre)))+''.join(list(reversed(S)))+suf)

s=list(input())
q=int(input())
rv=False
right=[]
left=[]
for _ in range(q):
  query=input()
  if query[0]=='1':
    rv=not rv
  else:
    _,f,c=query.split()
    if f=='1' and rv==False:
      left.append(c)
    elif f=='1' and rv==True:
      right.append(c)
    elif f=='2' and rv==False:
      right.append(c)
    elif f=='2' and rv==True:
      left.append(c)
if not rv:
  left.reverse()
  print((''.join(left)+''.join(s)+''.join(right)))
else:
  right.reverse()
  s.reverse()
  print((''.join(right)+''.join(s)+''.join(left)))


from collections import deque
d = deque(input())
n = int(input())
p=[]
flg = 0
for i in range(n):
  p = list(input().split())
  #print(p)
  if p[0] == "1":
    flg ^= 1 # flg == 1 の場合は左右反転
    #print(flg)
  else:    
    if p[1] == "1": # 1の場合は先頭
      if flg == 1: # 1の場合は反転
        d.append(p[2])
      else:
        d.appendleft(p[2]) # 左から入れる
    else:
      if flg == 1:
        d.appendleft(p[2]) # 左から入れる
      else:
        d.append(p[2])
  
if flg == 1:
  d.reverse()
a =""
for i in d:
  a += i
print(a)

from collections import deque
S=deque(input())
Q=int(input())

s=1
for i in range(Q):
  A = list(map(str,input().split()))
  if A[0]=='1':s*=-1;continue
  if A[1]=='1' and s==1:S.appendleft(A[2])
  elif A[1]=='2' and s==-1:S.appendleft(A[2])
  else:S.append(A[2])
  
if s==-1:S.reverse()
print((''.join(S)))


s = input()
q = int(input())
flag = 1
f = ''
b = ''
for i in range(q):
  query = list(map(str, input().split()))
  if query[0] == '1':
    flag *= -1
  else:
    if flag == 1:
      if query[1] == '1':
        f += query[2]
      else:
        b += query[2]
    else:
      if query[1] == '1':
        b += query[2]
      else:
        f += query[2]
ans = f[::-1] + s + b
if flag == -1:
  ans = ans[::-1]
print(ans)

S = input()
Q = int(input())
reverse = False
left = ''
right = ''

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        reverse = not reverse
    else:
        F = q[1]
        C = q[2]
        if not reverse:
            if F == '1':
                left = C + left
            else:
                right += C
        else:
            if F == '1':
                right += C
            else:
                left = C + left

S = left + S + right
if not reverse:
    print(S)
    return
else:
    print((S[::-1]))
    return


from collections import deque

def main():

    s = deque(input())
    q = int(input())

    flag = 0
    query = []

    for _ in range(q):
        temp = input().split()
        if len(temp) == 1:
            flag += 1
        else:
            query.append(temp + [flag%2])

    for q in query:
        if q[-1] == 0:
            if q[1] == "1":
                s.appendleft(q[2])
            else:
                s.append(q[2])
        else:
            if q[1] == "1":
                s.append(q[2])
            else:
                s.appendleft(q[2])

    if flag % 2 == 1:
        print(("".join(list(s)[::-1])))
    else:
        print(("".join(s)))

main()


import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])

from collections import deque

z=list(input())
Q=deque()
for i in z:
  Q.append(i)
q=int(input())

cnt=0

for i in range(q):
  x=input()
  if x[0]=='1':
    cnt+=1
    cnt%=2
    
  elif x[0]=='2':
    if x[2]=='1':
        if cnt%2==0:
            Q.appendleft(x[4])
        else:
            Q.append(x[4])

    else:
        if cnt%2==0:
            Q.append(x[4])
        else:
            Q.appendleft(x[4])
      
if cnt%2==1:
  Q.reverse()


print(''.join(Q))

s = input()
q = int(input())

h = 0
t =''
b =''

for i in range(q):
    x = list(input().split())
    
    if len(x) == 1:
        h += 1
    
    elif h % 2 == 0:
        if x[1] == '1':
            t = (x[-1]) + t
        else:
            b += (x[-1])
    
    
    elif h % 2 == 1:
        if x[1] == '1':
            b += (x[-1])
        else:
            t = (x[-1]) + t
    
if h % 2 == 0:
    print(t+s+b)
    
else:
    s=t+s+b
    s=s[::-1]
    print(s)

S = input()
Q = int(input())
T = ""

for q in range(Q):
  que = input().split()
  if que[0]=="1":
        S,T = T,S
  else:
    if que[1]=="1":
      T+=que[2]
    else:
      S+=que[2]

print(T[::-1]+S)

S = input()
Q = int(input())
upside_down = False
front = ""

for i in range(Q):
    l = list(map(str,input().split()))
    
    if l[0] == "1":
        if upside_down == False:
            upside_down = True
        else:
            upside_down = False
    else:
        F,C = l[1],l[2]
        
        if upside_down:
            if F == "1":
                S = S + C
            else:
                front += C
        else:
            if F == "1":
                front += C
            else:
                S = S + C

front = front[::-1]
S = front + S

if upside_down:
    S = S[::-1]

print(S)

import sys
import math
import itertools
import collections
from collections import deque
from collections import defaultdict

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD2 = 998244353
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def main():
    S = SI()
    Q = NI()
    
    que = deque(list(S))
    
    reverse = False
    
    for q in range(Q):
        query = input()

        if query == "1":
            if reverse == False:
                reverse = True
            else:
                reverse = False
        else:
            x,y,z = map(str,query.split())
            if reverse == False:
                if y == "1":
                    que.appendleft(z)
                else:
                    que.append(z)
            else:
                if y == "1":
                    que.append(z)
                else:
                    que.appendleft(z)

    if reverse==True:
        print("".join(reversed(list(que))))
    else:
        print("".join(list(que)))#print(x,y,z)



def __starting_point():
    main()
__starting_point()

import math
import collections
from itertools import product

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

s = input()
q = ii()
query = [input().split() for _ in range(q)]

front = []
back = []

cnt1 = 0
for i in range(q):
    if query[i][0] == '1':
        cnt1 += 1
    else:
        if cnt1 % 2 == 0:
            if query[i][1] == '1':
                front.append(query[i][2])
            else:
                back.append(query[i][2])
        else:
            if query[i][1] == '1':
                back.append(query[i][2])
            else:
                front.append(query[i][2])

if cnt1 % 2 == 0:
    print(''.join(front[::-1]) + s + ''.join(back))
else:
    print(''.join(back[::-1]) + s[::-1] + ''.join(front))

from collections import deque
s = deque(input())
q = int(input())
rev = False

for i in range(q):
  query = input().split()
  
  if query[0] == '1':
    rev = not rev
  else:
    if query[1] == '1':
      if rev: 
        s.append(query[2])
      else:
        s.appendleft(query[2])
    elif query[1] == '2':
      if rev:
        s.appendleft(query[2])
      else:
        s.append(query[2])
s = list(s)
if rev:
  s = s[::-1]

print(*s, sep='')

from collections import deque
S=deque()
f=input
S.extend(list(f()))
F=1
 
for _ in range(int(f())):
 q=input()
 if q[0]=='1':F=1-F
 else:
   if int(q[2])+F==2:S.appendleft(q[4])
   else:S.append(q[4])
print(''.join([list(S)[::-1],S][F]))

S,Q=input(),int(input())
l,r='',''
reverse=0
for i in range(Q):
    T=input().split()
    if T[0]=='1':reverse=0 if reverse else 1
    else:
        if T[1]=='1':
            if reverse:r=r+T[2]
            else:l=T[2]+l
        else:
            if reverse:l=T[2]+l
            else:r=r+T[2]
if reverse:
    s=list(l+S+r);s.reverse()
    print(''.join(s))
else:
    print(l+S+r)

S = input()
Q = int(input())

reverse = False
left = ''
right = ''

for _ in range(Q):
    q = input().split()
    if q[0] == '1':
        reverse = not reverse
    else:
        F = q[1]
        C = q[2]
        if reverse == False:
            if F =='1':
                left = C + left
            else:
                right += C
        
        else:
            if F == '1':
                right += C
            else:
                left = C + left

S = left + S + right
if reverse == False:
    print(S)
    return
else:
    print((S[::-1]))
    return


s = input()
q = int(input())
head = ''
tail = ''
rev = 0

for _ in range(q):
    T = list(input().split())
    if T[0] == '1':
        head, tail = tail, head
        rev += 1
    else:
        if T[1] == '1':
            head += T[2]
        else:
            tail += T[2]

if rev%2 == 0:
    print((head[::-1]+s+tail))
else:
    print((head[::-1]+s[::-1]+tail))


from collections import deque
s = list(input())
q = int(input())

d = deque()
for i in s:
    d.append(i)

c = 1
for _ in range(q):
    t = list(input().split())
    if t[0] == '1':
        c *= -1
    else:
        if t[1] == '1':
            if c == 1:
                d.appendleft(t[2])
            else:
                d.append(t[2])
        else:
            if c == 1:
                d.append(t[2])
            else:
                d.appendleft(t[2])

print(''.join(list(d)[::c]))

import sys
S = input()
A = ''
input()
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            A = A + i[4]
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            A = A + i[4]
        else:
            S = S + i[4]

ans = A[::-1] + S
print((ans[::key]))


from collections import deque
d=deque(input())
q=int(input())
ans=1
for i in range(q):
    a=input()
    if int(a[0])==1:
        ans=ans*(-1)
    else:
        if ans==1:
            if int(a[2])==1:
                d.appendleft(a[4])
            else:
                d.append(a[4])
        else:
            if int(a[2])==1:
                d.append(a[4])
            else:
                d.appendleft(a[4])
if ans==1:
    for i in range(len(d)):
        print(d[i],end="")
else:
    d.reverse()
    for i in range(len(d)):
        print(d[i],end="")
        

from collections import deque
s = deque(input())
rev = 0
q = int(input())
for i in range(q):
    query = list(map(str, input().split()))
    if query[0]=="1":
        rev += 1
        rev %= 2
    else:
        f, c = query[1:]
        if f=="1":
            if rev:
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if rev:
                s.appendleft(c)
            else:
                s.append(c)
s = "".join(s)
if rev:
    print(s[::-1])
else:
    print(s)

S = input()
Q = int(input())
Query = list(input().split() for _ in range(Q))

count = 0
L, R = "", ""

for i in range(Q):
  if Query[i][0] == "1": count += 1
  else:
    if Query[i][1] == "1":
      if count % 2 == 0: L = Query[i][2] + L
      else: R += Query[i][2]
    else:
      if count % 2 == 0: R += Query[i][2]
      else: L = Query[i][2] + L

if count % 2 == 0: print(L + S + R)
else: print(R[::-1] + S[::-1] + L[::-1])

from collections import deque

S = deque(input())
Q = int(input())

mode = 0
for _ in range(Q):
    T, *FC = input()
    if T == "1":
        mode ^= 1
        continue
    _, F, _, C = FC
    if int(F)+mode == 2: S.append(C)
    else: S.appendleft(C)
print("".join(reversed(S)if mode else S))

import sys
#import time
from collections import deque, Counter, defaultdict
#from fractions import gcd
import bisect
import heapq
import math
import itertools
#import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**18
MOD = 1000000007
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
mod = 998244353

s = rs()
q = ri()
cnt=0
head, tail = [], []
for i in range(q):
    qry = list(input().split())
    if len(qry)==3:
        if int(qry[1])%2 ^ (cnt%2) :
            head.append(qry[2])
        else:
            tail.append(qry[2])
    else:
        cnt+=1
ans = "".join(head[::-1]) +s+ "".join(tail) 
print((ans if cnt%2 == 0 else ans[::-1]))
    


from collections import deque
s=deque(list(input()))
n=int(input())
count=0


for i in range(n) :
    x=input()
    if x[0]=="1" :
        count+=1
        count%=2

    elif x[2]=="1" :
        if count%2==0 :
            s.appendleft(x[4])
        else :
            s.append(x[4])
    else :
        if count%2==0 :
            s.append(x[4])
        else :
            s.appendleft(x[4])


if count%2==1 :
    s.reverse()

print("".join(s))

S = input()
Q = int(input())

lS = ''
for _ in range(Q):
    query = input().split()
    if query[0] == '1':
        lS, S = S, lS
    else:
        if query[1] == '1':
            lS += query[2]
        else:
            S += query[2]

print(lS[::-1] + S)

from collections import deque
s = str(input())
q = int(input())
stat = 0
l = []
a = deque()
b = deque()
for i in range(q):
    l = list(map(str, input().split()))
    t = int(l[0])
    if t == 1:
        stat += 1
    else:
        f = int(l[1])
        c = l[2]
        if stat % 2 == 0:
            if f == 1:
                a.appendleft(c)
            else:
                b.append(c)
        else:
            if f == 1:
                b.append(c)
            else:
                a.appendleft(c)

#print(a, b, stat % 2)
ans = ''.join(a)+s+''.join(b)
if stat % 2 == 1:
    ans = ans[::-1]
print(ans)


# author:  Taichicchi
# created: 21.09.2020 20:00:43

import sys

S = input()

Q = int(input())

rev = 0

front = []
end = []

for q in range(Q):
    query = input().split()
    if query[0] == "1":
        rev = 1 - rev
    else:
        if ((rev == 0) & (query[1] == "1")) | ((rev == 1) & (query[1] == "2")):
            front.append(query[2])
        else:
            end.append(query[2])

front = "".join(front)
end = "".join(end)


if rev:
    print((end[::-1] + S[::-1] + front))
else:
    print((front[::-1] + S + end))


from collections import deque
def main():
    s = list(input())
    q = int(input())
    query = []
    que = deque(s)
    f = False
    for i in range(q):
        query.append(input().split(" "))
    for i in range(q):
        if query[i][0] == '1':
            f = not f
        else:
            if f:
                if query[i][1] == '2':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
            else:
                if query[i][1] == '1':
                    que.appendleft(query[i][2])
                else:
                    que.append(query[i][2])
    if f:
        que.reverse()
    print("".join(que))

def __starting_point():
    main()
__starting_point()

import sys
from collections import deque


def LS():
    return list(input().split())


S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
    A = LS()
    if A[0] == "1":
        rev += 1
        rev %= 2
    else:
        if A[1] == "1":
            if rev == 0:
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if rev == 0:
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev == 0:
    print((''.join(S)))
else:
    S.reverse()
    print((''.join(S)))


from collections import deque

s = list(input())
q = int(input())
t = [list(map(str,input().split())) for _ in range(q)]

d = deque(s)

cnt = 0
for i in range(q):
  if len(t[i]) == 1:
    cnt += 1
  else:
    if (int(t[i][1])+cnt) % 2 != 0:
      d.appendleft(t[i][2])
    else:
      d.append(t[i][2])
      
if cnt%2 != 0:
  d = list(d)[::-1]
print(''.join(d))

S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
forward = 1
f = ''
b = ''
for i in range(Q):
    if query[i][0] == '1':
        forward *= -1
    else:
        if query[i][1] == '1':
            if forward == 1:
                f += query[i][2]
            else:
                b += query[i][2] 
        else:
            if forward == 1:
                b += query[i][2] 
            else:
                f += query[i][2]
S = ''.join(list(reversed(f))) + S + b

if forward == -1:
    ans = ''.join(list(reversed(S)))
else:
    ans = S
print(ans)


from collections import deque
import sys


def input():
    return sys.stdin.readline().strip()


q = deque(input())
Q = int(input())
flipped = False
for _ in range(Q):
    q_t, *q_b = input().split()
    if q_t == "1":
        flipped = not flipped
    else:
        F, C = q_b
        if (F == "2" and not flipped) or (F == "1" and flipped):
            q.append(C)
        else:
            q.appendleft(C)
q = list(q)
if flipped:
    print(("".join(q[::-1])))
else:
    print(("".join(q)))