Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.insert(0, i[4])

s = "".join(ans)

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]

k= 0

for i in li:
    if i == "1":
        k += 1
    else:
        
        if (int(i[2])+k) % 2 == 0:
            s = s + i[4]
        else:
            s = i[4] + s

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


Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.insert(0, i[4])

s = "".join(ans)

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]

k= 0

for i in li:
    if i == "1":
        k += 1
    else:
        
        if (int(i[2])+k) % 2 == 0:
            s = s + i[4]
        else:
            s = i[4] + s

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]

k= 0

for i in range(q):
    if li[i] == "1":
        k += 1
    else:
        li3 = li[i].split()
        if (int(li3[1])+k) % 2 == 0:
            s = s + li3[2]
        else:
            s = li3[2] + s

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())

li = [input() for i in range(q)]

k= 0

for i in range(q):
    if li[0] == 1:
        k += 1
    else:
        li3 = li[i].split()
        if (int(li3[1])+k) % 2 == 0:
            s = s + li3[2]
        else:
            s = li3[2] + s

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

li = [input() for i in range(q)]

li2 = [0]*q
k= 0

for i in range(q):
    if len(li[i]) == 1:
        k += 1
        li2[i] = k
    else:
        li2[i] = k
        li3 = li[i].split()
        if (int(li3[1])+k) % 2 == 0:
            s = s + li3[2]
        else:
            s = li3[2] + s

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

Fixed submission:
from collections import deque
s = input()
q = int(input())

li = [input() for i in range(q)]
k = 0
ans = [s]
ans = deque(ans)

for i in li:
    if i == "1":
        k += 1
    else:
        if (int(i[2]) + k) % 2 == 0:
            ans.append(i[4])
        else:
            ans.appendleft(i[4])

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