CodeEff/ECCO huggingface dataset:
# Original solution
# coding: utf-8
S = input().split()
Q = int(eval(input()))

def pop(left, right, rev, f, c):
    left_ = left
    if rev == 1:
        if f == '1':
            left_ = left[::-1]
            left_.append(c)
            left_ = left_[::-1]
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left_ = left[::-1]
            left_.append(c)
            left_ = left_[::-1]
    return left_, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print((''.join(left+S+right)[::rev]))

# Optimized solution
# coding: utf-8
S = input().split()
Q = int(eval(input()))

def pop(left, right, rev, f, c):
    if rev == 1:
        if f == '1':
            left.append(c)
        else:
            right.append(c)
    else:
        if f == '1':
            right.append(c)
        else:
            left.append(c)
    return left, right


left, right = [], []
rev = 1
for _ in range(Q):
    que = input().split()
    if que[0] == '1':
        rev *= -1
        continue
    if que[0] == '2':
        left, right = pop(left, right, rev, *que[1:])
print((''.join(left[::-1]+S+right)[::rev]))
# Original solution
def solve(string):
    s, q, *qs = string.split("\n")
    for _q in qs:
        if _q == "1":
            s = s[::-1]
            continue
        _, f, c = _q.split()
        s = c + s if f == "1" else s + c
    return s


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))


# Optimized solution
def solve(string):
    s, q, *qs = string.split("\n")
    pre = []
    post = []
    r = False
    for _q in qs[::-1]:
        if _q == "1":
            r = not r
            continue
        _, f, c = _q.split()
        if r and f == "2" or not r and f == "1":
            pre.append(c)
        else:
            post.append(c)
    pre, post = "".join(pre), "".join(post[::-1])
    return pre + s[::-1] + post if r else pre + s + post


if __name__ == '__main__':
    import sys
    print((solve(sys.stdin.read().strip())))
# Original solution
from collections import deque

def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

s = deque(inp())
q = iinp()

l = deque()

p = 0
o = 1

for i in range(q):
  a = inps()
  if o == 1 and a[0] == 1:
    continue
  if a[0] == "2":
    if a[1] == "1":
      if p == 0:
        l.appendleft(a[2])
        o += 1
      else:
        s.appendleft(a[2])
        o += 1
    else:
      if p == 0:
        s.append(a[2])
        o += 1
      else:
        l.append(a[2])
        o += 1
  if a[0] == "1":
    if p == 0:
      p = 1
    else:
      p = 0
    s.reverse()
    l.reverse()

if p == 0:
  for i in l:
    print(i,end="")
  for i in s:
    print(i,end="")
  print("")
else:
  for i in s:
    print(i,end="")
  for i in l:
    print(i,end="")
  print("")


# Optimized solution
def inp():
    return input()
def iinp():
    return int(input())
def inps():
    return input().split()
def miinps():
    return map(int,input().split())
def linps():
    return list(input().split())
def lmiinps():
    return list(map(int,input().split()))
def lmiinpsf(n):
    return [list(map(int,input().split()))for _ in range(n)]

s = list(inp())
q = iinp()

l = []

p = 0
o = 1

for i in range(q):
  a = inps()
  if o == 1 and a[0] == 1:
    continue
  if a[0] == "2":
    if a[1] == "1":
      if p == 0:
        l.append(a[2])
        o += 1
      else:
        s.append(a[2])
        o += 1
    else:
      if p == 0:
        s.append(a[2])
        o += 1
      else:
        l.append(a[2])
        o += 1
  if a[0] == "1":
    if p == 0:
      p = 1
    else:
      p = 0

if p == 0:
  for i in range(len(l)):
    print(l[len(l)-1-i],end="")
  for i in s:
    print(i,end="")
  print("")
else:
  for i in range(len(s)):
    print(s[len(s)-1-i],end="")
  for i in l:
    print(i,end="")
  print("")
# Original solution
import sys
input = sys.stdin.readline

S=list(input()[:-1])
Q=int(input()[:-1])
f=0

for _ in range(Q):
    q=input().split()
    if int(q[0])==1:
        f = (f+1)%2
    if int(q[0])==2:
        if int(q[1])==1:
            if f==0:
                SS=[q[2]]
                SS.extend(S)
                S=SS
            else:
                S.append(q[2])
        else:
            if f==0:
                S.append(q[2])
            else:
                SS=[q[2]]
                SS.extend(S)
                S=SS
if f==0:
    print(("".join(S)))
else:
    print(("".join(S[::-1])))


# Optimized solution
import sys
input = sys.stdin.readline

S=list(input()[:-1])
Q=int(input()[:-1])
f=0
back=[]
forward=[]

for _ in range(Q):
    q=input().split()
    if int(q[0])==1:
        f = (f+1)%2
    if int(q[0])==2:
        if int(q[1])==1:
            if f==0:
                forward.append(q[2])
            else:
                back.append(q[2])
        else:
            if f==0:
                back.append(q[2])
            else:
                forward.append(q[2])

if f==0:
    print(("".join(forward[::-1]+S+back)))
else:
    print(("".join((forward[::-1]+S+back)[::-1])))
# Original solution
# D - String Formation
from collections import deque


def main():
    S = input().rstrip()
    Q = int(eval(input()))
    queue = deque(S)
    to_beginning, to_end = queue.appendleft, queue.append
    is_reversed = 0
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            is_reversed ^= 1
            continue
        com, c = query[1], query[2]
        if com == "1":
            if not is_reversed:
                to_beginning(c)
            else:
                to_end(c)
        else:
            if not is_reversed:
                to_end(c)
            else:
                to_beginning(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
# D - String Formation
from collections import deque


def main():
    S = input().rstrip()
    Q = int(eval(input()))
    queue = deque(S)
    to_beginning, to_end = queue.appendleft, queue.append
    is_reversed = False
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            to_beginning, to_end = to_end, to_beginning
            is_reversed = not is_reversed
            continue
        com, c = query[1], query[2]
        if com == "1":
            to_beginning(c)
        else:
            to_end(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
# D - String Formation
from collections import deque


def main():
    S = input().rstrip()
    Q = int(eval(input()))
    queue = deque(S)
    is_reversed = 0
    for _ in range(Q):
        query = input().split()
        if query[0] == "1":
            is_reversed ^= 1
            continue
        com, c = query[1], query[2]
        if com == "1":
            if not is_reversed:
                queue.appendleft(c)
            else:
                queue.append(c)
        else:
            if not is_reversed:
                queue.append(c)
            else:
                queue.appendleft(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
# D - String Formation
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines


def main():
    S = readline().rstrip()
    _ = readline()
    queries = readlines()
    queue = deque(S)
    to_beginning, to_end = queue.appendleft, queue.append
    is_reversed = 0
    for query in queries:
        if query[0] == "1":
            to_beginning, to_end = to_end, to_beginning
            is_reversed ^= 1
            continue
        com, c = query[2], query[4]
        if com == "1":
            to_beginning(c)
        else:
            to_end(c)
    ans = "".join(queue) if not is_reversed else "".join(reversed(queue))
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
s = list(input())
n = int(input())
head = []
tail = []

cnt = 0
for _ in range(n):
    li = list(input().split())
    if li[0] == '1':
        head, tail = tail, head
        s = s[::-1]
        cnt += 1
    else:
        if li[1] == '1':
            head += li[2]
        else:
            tail += li[2]

ans = head[::-1] + s + tail
print(*ans , sep='')


# Optimized solution
s = list(input())
n = int(input())
head = []
tail = []

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

if cnt % 2 != 0:
    s = s[::-1]
    
ans = head[::-1] + s + tail
print(*ans , sep='')
# Original solution
s = list(input())
n = int(input())
head = []
tail = []

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

if cnt % 2 != 0:
    s = s[::-1]

ans = head[::-1] + s + tail
print(*ans , sep='')


# Optimized solution
s = list(input())
n = int(input())
head = []
tail = []

cnt = 0
for _ in range(n):
    li = list(input().split())
    if li[0] == '1':
        head, tail = tail, head
        cnt += 1
    else:
        if li[1] == '1':
            head.append(li[2])
        else:
            tail.append(li[2])

if cnt % 2 != 0:
    s = s[::-1]

ans = head[::-1] + s + tail
print(*ans , sep='')
# Original solution
import sys
input = sys.stdin.readline

s = input().strip('\n')
q = int(input().strip('\n'))

j = ''.join
turn = 0
for _ in range(q):
    query = input().strip('\n')
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = j([c, s])
            else:
                s = j([s, c])
        else:
            if turn % 2 == 0:
                s = j([s, c])
            else:
                s = j([c, s])

if turn % 2 == 0:
    print(s)
else:
     print((s[::-1]))

# Optimized solution
import sys
input = sys.stdin.readline

s = input().strip()
q = int(eval(input()))
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print((right[::-1] + s[::-1] + left))
else:
    print((left[::-1] + s + right))
# Original solution
from collections import deque

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

d = deque(s)

for _ in range(q):
  Q = list(input().split())
  
  if Q[0]=='1':
    d = deque(reversed(d))
  elif Q[0]=='2':
    if Q[1]=='1':
      d.appendleft(Q[2])
    elif Q[1]=='2':
      d.append(Q[2])

print(*d, sep='')


# Optimized solution
from collections import deque

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

d = deque(s)
inv = 0

for _ in range(q):
  Q = list(input().split())
  
  if Q[0]=='1':
    inv += 1
  elif Q[0]=='2':
    if Q[1]=='1':
      if inv%2==0:
        d.appendleft(Q[2])
      else:
        d.append(Q[2])
    elif Q[1]=='2':
      if inv%2==0:
        d.append(Q[2])
      else:
        d.appendleft(Q[2])

if inv%2==0:
  print(*d, sep='')
else:
  print(*deque(reversed(d)), sep='')
# Original solution
import sys
input = sys.stdin.readline

def main():
    S = input().replace('\n', '')
    Q = int(eval(input()))

    for _ in range(Q):
        query = input().split()
        if len(query) == 1:
            S = S[::-1]
        else:
            T, F, C = query
            if int(F) == 1:
                S = C + S
            else:
                S = S + C
    print(S)


main()

# Optimized solution
import sys
input = sys.stdin.readline

def main():
    S = input().replace('\n', '')
    Q = int(eval(input()))

    flg = 0
    head = ""
    tail = ""
    for _ in range(Q):
        query = input().split()
        if len(query) == 1:
            head, tail = tail, head
            flg += 1
        else:
            T, F, C = query
            if int(F) == 1:
                head += C
            else:
                tail += C
    if flg % 2:
        print((head[::-1] + S[::-1] + tail))
    else:
        print((head[::-1] + S + tail))
main()
# Original solution
import sys
input = sys.stdin.readline

s = input().split()[0]
q = int(eval(input()))

for _ in range(q):
    q_i = input().split()
    if len(q_i) == 1:
        s = s[::-1]
    else:
        _, f, c = q_i
        f = int(f)
        if f == 1:
            s = c + s
        else:
            s = s + c

print(s)

# Optimized solution
import sys
input = sys.stdin.readline

s = input().split()[0]
q = int(eval(input()))

left, right = [], []
state = 1
for _ in range(q):
    q_i = input().split()
    if len(q_i) == 1:
        state = (state)%2 + 1
    else:
        _, f, c = q_i
        f = int(f)
        if (f+state)%2 == 0:
            left += [c]
        else:
            right += [c]
if state == 1:
    print((''.join(left[::-1]) + s + ''.join(right)))
else:
    print((''.join(right[::-1]) + s[::-1] + ''.join(left)))
# Original solution
#初期入力
import sys
input = sys.stdin.readline
S = input().split()
S=S[0]
Q = int(eval(input()))
FQ_dic =tuple()
rev =0
for i in range(Q):
    FQ_dic =tuple(input().split())

    if      FQ_dic[0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし   
        if      FQ_dic[1]=="1":     #後ろにつける
            if rev %2 ==0:
                    S = FQ_dic[2] + S
            else:
                    S = S +FQ_dic[2] 
        else: #                      #前につける
            if rev %2 ==0:
                    S = S + FQ_dic[2]
            else:        
                    S = FQ_dic[2] + S
if rev %2 ==0:
    print(S)
else:
    print((S[::-1]))

# Optimized solution
#前・左につける変数、後ろ・右につける変数を用意して最後に足す
#前・左は最後にひっくり返す（abc ⇒cba)

#初期入力
import sys
input = sys.stdin.readline
S = input()
S=S.strip("\n")
Q = int(input())
FQ_dic={}
for i in range(Q):
    FQ_dic[i] =input().split()

rev =0
front =""
back =""

for i in range(Q):
   # print(S) 

    if FQ_dic[i][0] =="1": #逆転する
                rev +=1
    else:                   #逆転なし  
        if FQ_dic[i][1]=="1":     #前=左につける 
            if rev %2 ==0:
                front += FQ_dic[i][2]
            else:
                back  += FQ_dic[i][2]  
        else: #                      #後ろ=右につける
            if rev %2 ==0:
                back  += FQ_dic[i][2]  
            else:        
                front += FQ_dic[i][2]
front =front[::-1]
S =front + S + back

if rev %2 ==0:
    print(*S,sep="")
else:
    print(*S[::-1],sep="")
# Original solution
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(eval(input()))

reverse = False

for _ in range(Q):
    s = input().strip()
    if s.startswith("1"):
        reverse = not reverse
    else:
        _, f, c = s.split()
        if f == "1":
            if reverse:
                S = S + c
            else:
                S = c + S
        else:
            if reverse:
                S = c + S
            else:
                S = S + c

if reverse:
    print((S[::-1]))
else:
    print(S)


# Optimized solution
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(eval(input()))

reverse = False

before = ""
after = ""

for _ in range(Q):
    s = input().strip()
    if s[0] == "1":
        reverse = not reverse
    else:
        _, f, c = s.split()
        if f == "1":
            if reverse:
                after = after + c
            else:
                before = c + before
        else:
            if reverse:
                before = c + before
            else:
                after = after + c

if reverse:
    print((after[::-1] + S[::-1] + before[::-1]))
else:
    print((before + S + after))
# Original solution
import sys
input = sys.stdin.readline

def sol():
    s=input().rstrip()
    q=int(eval(input()))
    x=0
    for i in range(q):
        l=tuple([i for i in input().split()])
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: s=l[2]+s
            else: s=s+l[2]
        elif l[1]=="2":
            if x==0: s=s+l[2]
            else: s=l[2]+s
    print((s if x==0 else s[::-1]))

if __name__=="__main__":
    sol()


# Optimized solution
import sys
input = sys.stdin.readline

def sol():
    s=input().rstrip()
    q=int(eval(input()))
    x=0
    a,b="",""
    for i in range(q):
        l=tuple([i for i in input().split()])
        if l[0]=="1":
            x=(x+1)%2
        elif l[1]=="1":
            if x==0: a=l[2]+a
            else: b=b+l[2]
        elif l[1]=="2":
            if x==0: b=b+l[2]
            else: a=l[2]+a
    s=a+s+b
    print((s if x==0 else s[::-1]))

if __name__=="__main__":
    sol()
# Original solution
from collections import deque
s = deque(input())
q = int(input())

for i in range(q):
    t = input()
    if len(t) == 1:
        s.reverse()
    else:
        if t[2] == "1":
            s.appendleft(t[4])
        else:
            s.append(t[4])

print(*s, sep="")



# Optimized solution
from collections import deque
s = deque(input())
q = int(input())
rev = 0

for i in range(q):
    t = input()
    if rev == 0:
        if len(t) == 1:
            rev = 1
        else:
            if t[2] == "1":
                s.appendleft(t[4])
            else:
                s.append(t[4])
    else:
        if len(t) == 1:
            rev = 0
        else:
            if t[2] == "1":
                s.append(t[4])
            else:
                s.appendleft(t[4])

if rev == 1:
    s.reverse()
print(*s, sep="")
# Original solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  q = int(eval(input()))
  state = 1
  swap = [0, 2, 1]
  for _ in range(q):
    x = input().strip()
    if x == '1':
      state *= -1
    else:
      _, f, c = x.split(' ')
      f = int(f)
      if state == -1:
        f = swap[int(f)]
      if f == 1:
        s = c + s
      else:
        s += c
  if state == -1:
    s = s[::-1]
  print(s)


  pass

if __name__=='__main__':
  main()



# Optimized solution
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  s = input().strip()
  q = int(eval(input()))
  state = 1
  swap = [0, 2, 1]
  ss = []
  es = []
  for _ in range(q):
    x = input().strip()
    if x == '1':
      state *= -1
    else:
      _, f, c = x.split(' ')
      f = int(f)
      if state == -1:
        f = swap[int(f)]
      if f == 1:
        ss.append(c)
      else:
        es.append(c)
  s = ''.join(ss[::-1]) + s + ''.join(es)
  if state == -1:
    s = s[::-1]
  print(s)

if __name__=='__main__':
  main()
# Original solution
'''
　 ∧_,,∧    究極奥義「WAがACになーれ！！」
　（`・ω・)つ━☆・*。
　⊂　　 ノ 　　　・゜+.
　 し’´Ｊ　　*・ 
'''
s=input()
a=[]
b=[]
now=1
q=int(input())
for i in range(q):
    x=list(input().split())
    if x[0]=="1":
        now*=-1
    else:
        if now==1 and x[1]=="2" or now==-1 and x[1]=="1":
            b.append(x[2])
        else:
            a.append(x[2])
if now==-1:
    ans=b[::-1]+list(s[::-1])+a
    print(*ans,sep="")
else:
    ans=a[::-1]+list(s)+b
    print(*ans,sep="")


# Optimized solution
s=input()
a=[]
b=[]
now=True
q=int(input())
for i in range(q):
    x=list(input().split())
    if x[0]=="1":
        now=not now
    else:
        if now and x[1]=="2" or not now and x[1]=="1":
            b.append(x[2])
        else:
            a.append(x[2])
if now:
    ans=a[::-1]+list(s)+b
else:
    ans=b[::-1]+list(s[::-1])+a
print(*ans,sep="")
# Original solution
from collections import deque

s = list(input())
q = int(input())
ans = deque(s)
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        ans.reverse()
    else:
        if arr[1] == '1':
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
print(*ans, sep='')


# Optimized solution
from collections import deque


s = list(input())
q = int(input())
ans = deque(s)
cnt = 0
for i in range(q):
    arr = list(map(str, input().split()))
    if arr[0] == '1':
        cnt += 1
        cnt %= 2
    else:
        if (arr[1] == '1' and cnt == 0) or (arr[1] == '2' and cnt == 1):
            ans.appendleft(arr[2])
        else:
            ans.append(arr[2])
if cnt == 0:
    print(*ans, sep='')
else:
    ans.reverse()
    print(*ans, sep='')
# Original solution
from collections import deque
s = deque(input())
q = int(input())
l = list(list(input().split()) for _ in range(q))
for i in l:
  if len(i)==1:
    s.reverse()
  else:
    a,f,c = i
    if f=="1":
      s.appendleft(c)
    else:
      s.append(c)
      
print(*s,sep="")
      


# Optimized solution
from collections import deque
s = deque(input())
q = int(input())
l = list(list(input().split()) for _ in range(q))
t = 0
for i in l:
  if len(i)==1:
    t += 1
  else:
    a,f,c = i
    if (f=="1" and t%2==0) or (f=="2" and t%2==1) :
      s.appendleft(c)
    else:
      s.append(c)
if t%2==1:
  s.reverse()
print(*s,sep="")
# Original solution
from collections import deque
import sys
input=sys.stdin.readline
moji=deque([])
s=input().rstrip()
for i in range(len(s)):
	moji.append(ord(s[i]))
q=int(eval(input()))
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		if f=="1":
			if rev%2==0:
				moji.appendleft(ord(c))
			else:
				moji.append(ord(c))
		else:
			if rev%2==0:
				moji.append(ord(c))
			else:
				moji.appendleft(ord(c))
ans=""
alph="abcdefghijklmnopqrstuvwxyz"
for i in range(len(moji)):
	ans+=alph[moji[i]-97]
if rev%2==0:
	print(ans)
else:
	print((ans[::-1]))


# Optimized solution
alph="abcdefghijklmnopqrstuvwxyz"
from collections import deque
import sys
input=sys.stdin.readline
moji=deque([])
s=input().rstrip()
for i in range(len(s)):
	for j in range(26):
		if s[i]==alph[j]:
			moji.append(j)
			break
q=int(eval(input()))
rev=0
for _ in range(q):
	qw=input().split()
	if qw[0]=="1":
		rev+=1
	else:
		f=qw[1]
		c=qw[2]
		for j in range(26):
			if c==alph[j]:
				x=j
				break
		if f=="1":
			if rev%2==0:
				moji.appendleft(x)
			else:
				moji.append(x)
		else:
			if rev%2==0:
				moji.append(x)
			else:
				moji.appendleft(x)
ans=""
r=[]
for i in range(len(moji)):
	r.append(moji.popleft())
for i in range(len(r)):
	ans+=alph[r[i]]
if rev%2==0:
	print(ans)
else:
	print((ans[::-1]))