Buggy python submission (verdict: Time Limit Exceeded):
def main():
	S=input()                                               # 1行1列
	Q=int(input())                                          # 1行1列
	Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意

	dir = 0 # 0が正常

	List = [S]

	for query in Q_LIST:
		if query[0] == '1':
			if dir == 0:
				dir = 1
			else:
				dir = 0

		if dir == 0:
			HEAD = '1'
			BACK = '2'
		else:
			HEAD = '2'
			BACK = '1'

		if query[0] == '2':
			if query[1] == HEAD:
				List.insert(0, query[2])
			if query[1] == BACK:
				List.append(query[2])

	S = ''.join(List)

	if dir == 0:
		print(S)
	else:
		print(S[::-1])

if __name__ == '__main__':
    main()


Fixed submission:
def main():
	S=input()                                               # 1行1列
	Q=int(input())                                          # 1行1列
	Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意
	 
	dir = 0 # 0が正常

	S_HEAD = ''
	S_BACK = ''

	for query in Q_LIST:
		if query[0] == '1':
			if dir == 0:
				dir = 1
			else:
				dir = 0
	 
		if dir == 0:
			HEAD = '1'
			BACK = '2'
		else:
			HEAD = '2'
			BACK = '1'
	 
		if query[0] == '2':
			if query[1] == HEAD:
				S_HEAD = query[2] + S_HEAD
			if query[1] == BACK:
				S_BACK =  S_BACK + query[2]

	S = S_HEAD + S + S_BACK

	if dir == 0:
		print(S)
	else:
		print(S[::-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
S=input()                                               # 1行1列
Q=int(input())                                          # 1行1列
Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意

dir = 0 # 0が正常

for query in Q_LIST:
	if query[0] == '1':
		if dir == 0:
			dir = 1
		else:
			dir = 0

	if dir == 0:
		HEAD = '1'
		BACK = '2'
	else:
		HEAD = '2'
		BACK = '1'

	if query[0] == '2':
		if query[1] == HEAD:
			S = query[2] + S 
		if query[1] == BACK:
			S =  S + query[2]

if dir == 0:
	print(S)
else:
	print(S[::-1])


Fixed submission:
def main():
	S=input()                                               # 1行1列
	Q=int(input())                                          # 1行1列
	Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意
	 
	dir = 0 # 0が正常

	S_HEAD = ''
	S_BACK = ''

	for query in Q_LIST:
		if query[0] == '1':
			if dir == 0:
				dir = 1
			else:
				dir = 0
	 
		if dir == 0:
			HEAD = '1'
			BACK = '2'
		else:
			HEAD = '2'
			BACK = '1'
	 
		if query[0] == '2':
			if query[1] == HEAD:
				S_HEAD = query[2] + S_HEAD
			if query[1] == BACK:
				S_BACK =  S_BACK + query[2]

	S = S_HEAD + S + S_BACK

	if dir == 0:
		print(S)
	else:
		print(S[::-1])

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
S=input()                                               # 1行1列
Q=int(input())                                          # 1行1列
Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意

for query in Q_LIST:
	if query[0] == '1':
		S = S[::-1]
	if query[0] == '2':
		if query[1] == '1':
			S = query[2] + S 
		if query[1] == '2':
			S =  S + query[2]

print(S)

Fixed submission:
def main():
	S=input()                                               # 1行1列
	Q=int(input())                                          # 1行1列
	Q_LIST=[input().split() for i in range(Q)]                # N行C列・・・Cは任意
	 
	dir = 0 # 0が正常

	S_HEAD = ''
	S_BACK = ''

	for query in Q_LIST:
		if query[0] == '1':
			if dir == 0:
				dir = 1
			else:
				dir = 0
	 
		if dir == 0:
			HEAD = '1'
			BACK = '2'
		else:
			HEAD = '2'
			BACK = '1'
	 
		if query[0] == '2':
			if query[1] == HEAD:
				S_HEAD = query[2] + S_HEAD
			if query[1] == BACK:
				S_BACK =  S_BACK + query[2]

	S = S_HEAD + S + S_BACK

	if dir == 0:
		print(S)
	else:
		print(S[::-1])

if __name__ == '__main__':
    main()