Problem C
Kitten of Chaos

Now, Klaus’ paw slowly executes his diabolical deed. His cute fluffy face radiates inadvertent innocence. Knowing that any intervention would only delay the inevitable, Karen wonders what will happen to the string her sister Kim wrote on the precious glass object. After all, it took Kim a whole week to gather all the bdpq letters that make up the string.
Can you describe to Karen what the string will look like from her point of view while it tumbles towards destruction?
While falling off the shelf, Karen’s precious glass object is subject to the following transformations, described as seen when looking at the object from the front.
-
h: horizontal flip, e.g. bbq becomes pdd
-
v: vertical flip, e.g. bbq becomes ppd
-
r: 180-degree rotation, e.g. bbq becomes bqq
No flips along or rotations about any other axes are possible.
Input
The input consists of:
-
One line with a string $s$ consisting of the letters bdpq ($1 \le |s| \le 5\cdot 10^5$), the string printed on the glass object as seen at the start of the fall.
-
One line with a string $t$ consisting of the letters hvr ($1 \le |t| \le 5\cdot 10^5$) giving the sequence of transformations in the order that they occur during the fall.
Output
Output the string that can be seen at the moment the glass object touches the ground and just before it shatters into pieces.
Sample Input 1 | Sample Output 1 |
---|---|
bbq h |
pdd |
Sample Input 2 | Sample Output 2 |
---|---|
bbq v |
ppd |
Sample Input 3 | Sample Output 3 |
---|---|
bbq r |
bqq |
Sample Input 4 | Sample Output 4 |
---|---|
ppbddbq hvrhv |
bqppqdd |