Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])

if reverse == 1: q.reverse()
for i in range(len(q)):
    print(q[i],end="")
print()

Fixed submission:
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
if reverse == 1: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()


Fixed submission:
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))

Buggy python submission (verdict: Runtime Error):
from collections import deque

S = input()
Q = int(input())
q = deque([S])
reverse = -1

for i in range(Q):
    print(reverse)
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
    print(reverse, q)
if reverse == 1: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()
        


Fixed submission:
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))

Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys

S = input()
Q = int(input())
q = deque([S])
reverse = False

for i in range(Q):
    X = sys.stdin.readline().split()
    if X[0] == "1":
        if reverse:
            reverse = False
        else:
            reverse = True
    elif X[0] == "2":
        if reverse:
            print(reverse)
            X[1] = str(3-int(X[1]))
        if X[1] == "1":
            q.appendleft(X[2])
        else:
            q.append(X[2])
        print(reverse, X[1], q)

if reverse: q.reverse()

for i in range(len(q)):
    print(q[i],end="")
print()

Fixed submission:
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))

Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  string s;
  cin >> s;
  string t;
  int q;
  cin >> q;
  rep(qi,q){
    int ty;
    cin >> ty;
    if (ty == 1){
      swap(s,t);
    }else{
      int f; char c;
      cin >> f >> c;
      if (f == 1){
	t += c;
      }else{
	s+=c;
      }}
  }
  reverse(t.begin(), t.end());
  t += s;
  cout << t << endl;
  return 0;
}

Fixed submission:
from collections import deque

q = deque(input())
Q = int(input())
reverse = -1

for i in range(Q):
    X = input().split()
    if X[0] == "1":
        reverse *= -1
    # if X[1] == "1":
    elif X[1] == "1":
        if reverse == -1:
            q.appendleft(X[2])
        else:
            q.append(X[2])
    elif X[1] == "2":
        if reverse == -1:
            q.append(X[2])
        else:
            q.appendleft(X[2])
# if reverse == 1: q.reverse()

if reverse == -1:
    print(''.join(q))
else:
    print(''.join(list(q)[::-1]))