read s
read q
r=false
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
			s="${s}${c}"
		else
			s="${c}${s}"
		fi
	else
		if $r;then
			s="${c}${s}"
		else
			s="${s}${c}"
		fi
	fi
done

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

echo $s
