Problem:


Score : 400 points

Problem Statement

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 1

a
4
2 1 p
1
2 2 c
1

Sample Output 1

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.

Sample Input 2

a
6
2 2 a
2 1 b
1
2 2 c
1
1

Sample Output 2

aabc

There will be Q = 6 operations. Initially, S is a.

Operation 1: S becomes aa.

Operation 2: S becomes baa.

Operation 3: S becomes aab.

Operation 4: S becomes aabc.

Operation 5: S becomes cbaa.

Operation 6: S becomes aabc.

Thus, the resulting string is aabc.

Sample Input 3

y
1
2 1 x

Sample Output 3

xy



Sample input:
a
4
2 1 p
1
2 2 c
1


Sample output:
cpa

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
for i in range(q):
        data = input().split()
        if len(data) == 1:
            if len(s) != 1:
                s = s[len(s)-1] + s[1:-1] + s[0]
        else:
            f = int(data[1])
            c = data[2]
            if f == 1:
                s = c + s
            else:
                s = s + c
            

print(s)

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
st = np.empty(0, dtype=str)
st = np.append(st, S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        st = np.flipud(st)
    else:
        a1 = int(a[1])
        if a1 == 1:
            st = np.insert(st, 0, a[2])
        else:
            st = np.append(st, a[2])
ans = ''.join(st)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
flip = 0
d = deque([s])
for i in range(q):
    query = input().split()
    if query[0] == '1':
        flip ^= 1
    else:
        f = int(query[1]) - 1
        c = query[2]
        if f ^ flip == 1:
            d.append(c)
        else:
            d.appendleft(c)
if flip:
    d.reverse()
print(''.join(d))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())

f = ''
b = ''
num = 0
for i in range(q):
    a = input().split()
    if len(a) == 1:
        num ^= 1
        f,b = b,f
    else :
        if a[1] == '1' :
            f = a[2] + f
        elif a[1] == '2' :
            b = b + a[2]

if num:
    print(f[::-1]+s[::-1]+b)
else:
    print(f[::-1]+s+b)

Submission status: Wrong Answer

Solution code:
S=list(input())
Q=int(input())
rev=False
tmp=0
for i in range(Q):
  query=list(input().split())
  if len(query)!=1:
    if rev:
      if query[1]=="1":
        S.append(query[2])
      elif query[1]=="2":
        S.insert(0,query[2])
    else:
      if query[1]=="1":
        S.insert(0,query[2])
      elif query[1]=="2":
        S.append(query[2])
  else:
    tmp+=1
    if rev:
      rev=False
    else:
      rev=True
if tmp%2==0:
  print(''.join(S))
else:
  print(S[::-1])

Submission status: Wrong Answer

Solution code:
import numpy as np
S = input()
st = np.empty(0, dtype=str)
st = np.append(st, S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        st = np.flipud(st)
    else:
        a1 = int(a[1])
        if a1 == 1:
            st = np.insert(st, 0, a[2])
        else:
            st = np.append(st, a[2])
ans = ''.join(st)
print(ans)

Submission status: Wrong Answer

Solution code:
#input
S = input()
Q = int(input())
P = [[]] * Q
for i in range(Q):
    P[i] = list(map(str, input().split()))

#output
flip = 0
F = [[]] * Q
cap = ""
tail = ""

for i in range(Q):
    if int(P[i][0]) == 1:
        flip += 1
    F[i] = flip

for i in range(Q):
    if int(P[i][0]) == 2:
        n = int(P[i][1])
        v = P[i][2]
        if F[i] % 2 == 0:
            if n == 1:
                cap = v + cap
            else:
                tail = tail + v
        else:
            if n == 1:
                tail = v + tail
            else:
                cap = v + cap

answer = ""
if F[-1] % 2 == 0:
    answer = cap + S + tail
else:
    answer = tail[-1::-1] + S[-1::-1] + cap[-1::-1]

print(answer)

Submission status: Wrong Answer

Solution code:
s=input()
q=int(input())

rev=1

for _ in range(0,q):
  n=input()
#  print(n[0:1])
  if n[0:1]=="1":
#    print("!")
    rev*=-1
  else:
    m=n.split()
    x=[]
    x.append(m[2])
    x.append(s)
    if (m[1]=="1" and rev==1) or (m[1]=="2" and rev==-1):
      s=''.join(x)
#      s=m[2]+s
    else:
      s=''.join(x)
#      s=s+m[2]
if rev==1:
  print(s)
else:
  print(s[::-1])

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())

f = ''
b = ''
num = 0
for i in range(q):
    a = input().split()
    if len(a) == 1:
        f = f[::-1]
        b = b[::-1]
        f,b = b,f
    else :
        if a[1] == '1' :
            f = a[2] + f
        elif a[1] == '2' :
            b = b + a[2]

print(f + s + b)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])

ans = ""
ans = "".join(que2)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
q_num = int(input())

t = True
for _ in range(q_num):
  q = input().split()
  if q[0] == "1":
    t = not t
  else:
    if not t:
      if q[1] == "1":
        s = q[2] + s
      else:
        s = s + q[2]
    else:
      if q[1] == "1":
        s = s + q[2]
      else:
        s = q[2] + s
        
if t:
  s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import sys
S = input()
st = np.empty(0, dtype=str)
st = np.append(st, S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        st = np.flipud(st)
    else:
        a1 = int(a[1])
        if a1 == 1:
            st = np.insert(st, 0, a[2])
        else:
            st = np.append(st, a[2])
ans = ''.join(st)
print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
ans = ""

for i in que2:
    ans += i
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())

f = ''
b = ''
for i in range(q):
    a = input().split()
    if len(a) == 1:
        f = f[::-1]
        b = b[::-1]
        f,b = b,f
    else :
        if a[1] == '1' :
            f = f + a[2]
        elif a[1] == '2' :
            b = b + a[2]

print(f + s + b)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import sys
S = input()
st = np.empty(0, dtype=str)
st = np.append(st, S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        l = len(st)
        tmp = st[0]
        st[0] = st[l-1]
        st[l-1] = tmp
    else:
        a1 = int(a[1])
        if a1 == 1:
            st = np.insert(st, 0, a[2])
        else:
            st = np.append(st, a[2])
ans = ''.join(st)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import sys
S = input()
st = []
st.append(S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        l = len(st)
        tmp = st[0]
        st[0] = st[l-1]
        st[l-1] = tmp
    else:
        a1 = int(a[1])
        if a1 == 1:
            tmp = st
            l = len(tmp)
            st = []
            st.append(a[2])
            for j in range(l):
                st.append(tmp[j])
        else:
            st.append(a[2])
ans = ''.join(st)
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import numpy as np
import sys
S = input()
st = []
st.append(S)
Q = int(input())
for i in range(Q):
    a = input().split()
    a0 = int(a[0])
    if a0 == 1:
        l = len(st)
        tmp = st[0]
        st[0] = st[l-1]
        st[l-1] = tmp
    else:
        a1 = int(a[1])
        if a1 == 1:
            tmp = st
            l = len(tmp)
            st = []
            st.append(a[2])
            for j in range(l):
                st.append(tmp[j])
        else:
            st.append(a[2])
l = len(st)
for i in range(l):
    sys.stdout.write(st[i])

Submission status: Wrong Answer

Solution code:
#input
S = input()
Q = int(input())
P = []
for i in range(Q):
    P.append(list(map(str, input().split())))

#output
T = "AB"
for i in range(Q):
    if len(P[i]) == 1:
        T = T[-1::-1]
    else:
        v = P[i][2]
        if int(P[i][1]) == 1:
            T = v + T
        else:
            T = T + v

if "AB" in T:
    S = T.replace("AB", S)
else:
    S = T.replace("AB", S[-1::-1])
                        
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
flip = 0
d = deque([s])
for i in range(q):
    query = input().split()
    if query[0] == '1':
        flip ^= 1
    else:
        f = int(query[1]) - 1
        c = query[2]
        if f ^ flip == 0:
            d.append(c)
        else:
            d.appendleft(c)
if flip:
    d.reverse()
print(''.join(d))

Submission status: Wrong Answer

Solution code:
s = input()
n = int(input())
Q = [list(map(str, input().split())) for i in range(n)]

for i in range(n):
    op = Q[i]
    if len(op) == 1:
        s = s[::-1]
    elif op[1] == 1:
        s = op[2] + s
    else:
        s = s + op[2]
print(s)

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
revS = S
for i in range(Q):
  query = input().split()
  if query[0] == '1':
    tmp = S
    S = revS
    revS = tmp
  elif query[0] == '2':
    if query[1] == '1':
      S = query[2] + S
      revS = revS + query[2]
    elif query[1] == '2':
      S = S + query[2]
      revS = query[2] + revS
  #print('S='+S+', revS='+revS)
print(S)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
res = deque([s])
rev = 1
for i in range(Q):
    if len(query[i])==1:
        rev *= -1
    else:
        f,c = query[i][1], query[i][2]
        if rev > 0:
            if f==1:
                res.appendleft(c)
            else:
                res.append(c)
        else:
            if f==1:
                res.append(c)
            else:
                res.appendleft(c)
res = ''.join(list(res))
print(res if rev > 0 else res[::-1])

Submission status: Wrong Answer

Solution code:
S = str(input())
Q = int(input())
query = [list(map(str,input().split())) for _ in range(Q)]
#print(query)
#
for i in range(Q):
    if query[i][0]=='1':
        S = S[-1]+S[1:-1]+S[0]
    elif query[i][0]=='2':
        if query[i][1]=='1':
            S = query[i][2] + S
        else:
            S = S + query[i][2]
print(S)

Submission status: Wrong Answer

Solution code:
S = str(input())
Q = int(input())
query = [list(map(str,input().split())) for _ in range(Q)]

for i in range(Q):
    if query[i][0]=='1':
        S = S[-1]+S[1:-1]+S[0]
    elif query[i][0]=='2':
        if query[i][1]=='1':
            S = query[i][2] + S
        else:
            S = S + query[i][2]
print(S)

Submission status: Wrong Answer

Solution code:
s=str(input())

N=int(input())
cnt=0
f=''
b=''
for i in range(N):
  inp=str(input())
  if len(inp)==1:
    cnt+=1
  else:
    F,c=int(inp[2]),inp[4]
    if F==1:
      if cnt%2==0:
        f=c+f
      else:
        b+=c
    else:
      if cnt%2==0:
        b+=c
      else:
        f=c+f
if cnt%2==0:
  print(f+s+b)
else:
  print(b+s+''.join(list(reversed(f))))

Submission status: Wrong Answer

Solution code:
s=list(str(input()))

N=int(input())

for i in range(N):
  inp=str(input())
  if len(inp)==1:
    start=s[0]
    end=s[-1]
    s[0]=end
    s[-1]=start
  else:
    f,c=int(inp[2]),inp[4]
    if f==1:
      s.insert(0,c)
    else:
      s.insert(len(s),c)
ans=''
for i in range(len(s)):
  ans+=s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

def main():
  s = input()
  for i in range(int(input())):
    values = input().split()
    if values[0] == '1':
      s = s[::-1]
    else:
      s = values[2] + s if values[1] == '1' else s + values[2]
    
  return s 
 
print(main())

Submission status: Wrong Answer

Solution code:
def main():
  mode = True
  s = input()
  for i in range(int(input())):
    temp = input()
    if temp[0] == '1':
      mode = not mode
      continue
    
    if temp[2] == 1:
      s = temp[4] + s if mode else s + temp[4]
    else:
      s = s + temp[4] if mode else temp[4] + s
      
  return s if mode else s[::-1]
 
print(main())

Submission status: Wrong Answer

Solution code:
from collections import deque

S = input()
Q = int(input())
ARR = []

mrr = list([])
for i in range(Q):
    arr = input().split(" ")

    mrr.append(int(arr[0]))
    ARR.append(arr)

reverseTotal = mrr.count(1)

def calculate(s,q,arr,reverseTotal):

    s = deque(list(s))

    for ar in arr:
        if int(ar[0]) == 1:
            reverseTotal = reverseTotal - 1

        if int(ar[0]) == 2:

            if int(ar[1]) == 1:
                if reverseTotal % 2 == 0:
                    s.appendleft(ar[2])
                else:
                    s.append(ar[2])
            else:
                if reverseTotal % 2 == 0:
                    s.append(ar[2])
                else:
                    s.appendleft(ar[2])
    print("".join(list(s)))



calculate(S,Q,ARR,reverseTotal)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

S = deque([s])
flip = False

for qi in Q:
    if int(qi[0]) == 1:
      flip = not flip
    else:
      f = int(qi[1]) 
      c = qi[2]
      if flip:
        f = 3-f    
      if f == 1:
        S.appendleft(c)
      else:
        S.append(c)

if flip:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

S = deque([s])
flip = False

for qi in Q:
    if int(qi[0]) == 1:
      flip = not flip
    else:
      if flip:
        qi[1] = 3-int(qi[1])
      
      if int(qi[1]) == 1:
        S.appendleft(qi[2])
      else:
        S.append(qi[2])

if flip:
    S.reverse()
print(''.join(list(S)))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

S = deque([s])
flip = False

for qi in Q:
    if int(qi[0]) == 1:
      flip = not flip
    else:
      if flip:
        qi[1] = 3-int(qi[1])
      
      if int(qi[1]) == 1:
        S.appendleft(qi[2])
      else:
        S.append(qi[2])

if flip:
    S.reverse()

ans = ''
for s in S:
  ans += s
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque

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

S = deque([s])
flip = False

for qi in Q:
    if int(qi[0]) == 1:
      flip = not flip
    else:
      if flip:
        qi[1] = 3-int(qi[1])
      
      if int(qi[1]) == 1:
        S.appendleft(qi[2])
      else:
        S.append(qi[2])

if flip:
    S.reverse()
print(''.join(S))

Submission status: Wrong Answer

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

for qi in Q:
    if int(qi[0]) == 1:
        s, t = t, s
    else:
        if int(qi[1])  == 1:
            t += qi[2]
        else:
            s += qi[2]
t[::-1]
t += s
print(t)

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

S = deque([s])
S_reverse = S.reverse
S_appendleft = S.appendleft
S_append = S.append

for i in Q:
  if int(i[0]) == 1:
    S_reverse()
  else:
    if int(i[1]) == 1:
      S_appendleft(i[2])
    else:
      S_append(i[2])
print(''.join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = input()
q = int(input())
Q = [list(map(str, input().split())) for _ in range(q)]

S = deque([s])
S_reverse = S.reverse
S_appendleft = S.appendleft
S_append = S.append

for i in Q:
  if int(i[0]) == 1:
    S_reverse()
  else:
    if int(i[1]) == 1:
      S_appendleft(i[2])
    else:
      S_append(i[2])
      
print(''.join(S))

Submission status: Wrong Answer

Solution code:
from collections import deque

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

Q = []
for _ in range(q):
    Q.append(list(map(str, input().split())))

S = deque([s])
for i in Q:
  if int(i[0]) == 1:
    S.reverse()
  else:
    if int(i[1]) == 1:
      S.appendleft(i[2])
    elif int(i[1]) == 2:
      S.append(i[2])
      
print(''.join(S))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
Q = [ list(input().split()) for _ in range(q) ]
count = 0
for i in range(q):
    t = int(Q[i][0])
    if t==1:
        count += 1
    else:
        f = int(Q[i][1])
        if count%2==0 and f==1:
            s = Q[i][2] + s
        elif count%2==0 and f==2:
            s = s + Q[i][2]
        elif count%2==1 and f==1:
            s = s + Q[i][2]
        elif count%2==1 and f==1:
            s = Q[i][2] + s
        else:
            pass
        count = 0

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

Submission status: Wrong Answer

Solution code:
S = input()
Q = int(input())
for i in range(Q):
    Qi = input().split()
    if Qi[0] == "1":
        topS = S[0]
        lastS = S[-1]
        n = len(S)
        if n != 0:
            if n == 2:
                S = lastS + topS
            else:
                S = lastS + S[1:n-1] + topS
    elif Qi[0] == "2":
        if Qi[1] == "1":
            S = Qi[2] + S
        elif  Qi[1] == "2":
            S = S + Qi[2]
print(S)

Submission status: Wrong Answer

Solution code:
s = []
s.append(input())
Q = int(input())
cnt = 0
for _ in range(Q):
    tmp = input().split()
    if tmp[0] == '1':
        cnt += 1
        continue
    else:
        if cnt % 2:
            pass
        else:
            s.reverse()
        if tmp[2] == 1:
            s.insert(0, tmp[2])
        else:
            s.append(tmp[2])
if cnt % 2:
    pass
else:
    s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque
s = deque(input())
q = int(input())

flag = 1
for i in range(q):
  st = input().split()
  if int(st[0]) == 1:
    flag *= -1
  else:
    tmp = int(st[1])*flag
    if tmp == 1 or -2:
      s.appendleft(st[2])
    else:
      s.append(st[2])

if flag == -1:
  s.reverse()
print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())

flag = 1
for i in range(q):
  st = input().split()
  if int(st[0]) == 1:
    flag *= -1
  else:
    tmp = int(st[1])*flag
    if tmp == 1 or -2:
      s = st[2] + s
    else:
      s = s + st[2]

if flag == -1:
  s = s[::-1]
print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())

flag = 1
for i in range(q):
  st = input().split()
  if int(st[0]) == 1:
    flag *= -1
  else:
    tmp = int(st[1])*flag
    if tmp == 1 or -2:
      s = st[2] + s
    else:
      s = s + st[2]

print(s)

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
Flag = True
right=''
left=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            left += c
        else:
            right += c

ans = right[::-1] + s + left
print(ans if not Flag else ans[::-1])

Submission status: Wrong Answer

Solution code:
s = input()
q = int(input())
Flag = True
back=''
front=''

for i in range(q):
    t = input()
    if t[0] == '1':
        Flag = not Flag
    else:
        _, f, c = t.split()
        if Flag == False and f == '2' or Flag == True and f == '1':
            front += c
        else:
            back += c

ans = back[::-1] + s + front
print(ans if not Flag else ans[::-1])

Submission status: Wrong Answer

Solution code:
S = input()
Q=int(input())
Query=[S]
flag = True
strF=[]
strB=[]
for i in range(Q):
  S2=input()
  if S2=="1":
    flag = not flag
  else:
    x=S2.split()
    if flag:
      if x[1]=="1":
        strF.append(x[2])
        #Query=[x[2]]+Query
      else:
        strB.append(x[2])
        #Query.append(x[2])
    else:
      if x[1]=="1":
        strB.append(x[2])
        #Query.append(x[2])
      else:
        strF.append(x[2])
        #Query=[x[2]]+Query

if flag==False:
  strB.reverse()
  Query=strB+Query+strF
else:
  strF.reverse()
  Query=strF+Query+strB
 
print("".join(Query))

Submission status: Wrong Answer

Solution code:
S = input()
Q=int(input())
Query=[S]
flag = True
strF=[]
strB=[]
for i in range(Q):
  S2=input()
  if S2=="1":
    flag = not flag
  else:
    x=S2.split()
    if flag:
      if x[1]=="1":
        strF.append(x[2])
        #Query=[x[2]]+Query
      else:
        strB.append(x[2])
        #Query.append(x[2])
    else:
      if x[1]=="1":
        strB.append(x[2])
        #Query.append(x[2])
      else:
        strF.append(x[2])
        #Query=[x[2]]+Query
strF.reverse()
Query=strF+Query+strB
if flag==False:
  Query.reverse()
 
print("".join(Query))

Submission status: Wrong Answer

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()
s=[i for i in input()]
x=0 ; st=[[],[]]
for _ in range(int(input())):
    inp=list(map(str,input().split()))
    if len(inp)==1: x^=1
    else: st[(int(inp[1])-1)^x].append(inp[2])
if x==0:
    st[0].reverse()
    ans=st[0]+s+st[1]
elif x==1:
    st[1].reverse()
    ans=st[1]+s+st[0]
print(''.join(ans))