read s
read q
r=false
head=""
tail=""
for i in `seq 1 $q`;do
	read m f c
	if [ $m == "1" ];then
		if $r;then
			r=false
		else
			r=true
		fi
	else
		if [ $f == "1" ];then
			if $r;then
				tail="${tail}${c}"
			else
				head="${c}${head}"
			fi
		else
			if $r;then
				head="${c}${head}"
			else
				tail="${tail}${c}"
			fi
		fi
	fi
done

if $r;then
	tail=`echo ${tail}|rev`
	head=`echo ${head}|rev`
	echo $tail$s$head
else
	echo $head$s$tail
fi
