Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = []
    s.append(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.insert(0,c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.insert(0,c)

    ans = ''.join(s)
    if head == "r":
        ans = ans[::-1]
    print(ans)
main()

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = []
    s.append(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.insert(0,c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.insert(0,c)

    ans = ''.join(s)
    if head == "r":
        ans = ans[::-1]
    print(ans)
main()

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = input()
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s = c + s
                else:
                    s = s + c
            else: # f == 2
                if head == "l":
                    s = s + c
                else:
                    s = c + s

    if head == "r":
        s = s[::-1]
    print(s)
main()

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = list(input())
    q = int(input())
    for i in range(q):
        d = input()
        if d[0] == "1":
            s.reverse()
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                s.insert(0, c)
            else: # f == 2
                s.append(c)

    print(''.join(s))

main()

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

def main():
    s = input()
    q = int(input())

    for i in range(q):
        d = input()
        if d[0] == "1":
            s = s[::-1]
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                s = c + s
            else: # f == 2
                s = s + c

    print(s)

main()

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

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

for i in range(q):
    d = input()
    if d[0] == "1":
        s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

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

for i in range(q):
    d = input()
    if d[:1] == "1":
        if not s[:1] * len(s) == s:
            s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()

Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3 ## -*- python -*-

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

for i in range(q):
    d = input()
    if d[:1] == "1":
        s = s[::-1]
    else: # 2
        dd = d.split()
        f = int(dd[1])
        c = dd[2]
        if f == 1:
            s = c + s
        else: # f == 2
            s = s + c

print(s)

Fixed submission:
#!/usr/bin/env python3 ## -*- python -*-
from collections import deque

def main():
    s = deque()
    s.extend(input())
    q = int(input())
    head = "l"
    for i in range(q):
        d = input()
        if d[0] == "1":
            if head == "l":
                head = "r"
            else:
                head = "l"
        else: # 2
            dd = d.split()
            f = int(dd[1])
            c = dd[2]
            if f == 1:
                if head == "l":
                    s.appendleft(c)
                else:
                    s.append(c)
            else: # f == 2
                if head == "l":
                    s.append(c)
                else:
                    s.appendleft(c)

    if head == "r":
        s.reverse()
    ans = ''.join(s)
    print(ans)
main()