Word Process Machine

Time Limit: 1 Second    Memory Limit: 32768 KB

It is year 7896 since Christ's birth. Intel Corp. engineers are developing new Pentium XXXIV processor optimized for�� no, not for floating point calculations critical multimedia games but for one strange word processing algorithm. The algorithm accepts a string of characters and produces the result string (which is initially empty) using only two simple processor instructions: GET (removes the first character of the source string and appends one to the end of the result string) and REVERSE (reverses the rest of the source string). Doesn't it looks strange the computer engineering still solves the problems we could solve (couldn't we?) at November the 4th, 2000, 5896 years ago? So, your goal here is to implement that word processing machine. Your program will be given the source string for the algorithm and algorithm itself encoded using those GET and REVERSE commands. The program should print the string which is the result of the application of the given algorithm to the given source string.


This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each input block is in the format indicated in the problem description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between output blocks.

Input

First line of the input contains single integer 1 <= N <= 500 - number of lines in an input string (each not longer than 80 characters). Following lines contain data that form an input string (newline characters, but not spaces should be ignored). The rest of the file (not more than 100000 characters) up to # character contains commands of the algorithm coded as the following: G - for GET, R - for REVERSE. The algorithm code can also contain newline and space characters that should be ignored.

Output

The output should contain the result of the algorithm application to the given string printed so that all lines (excluding probably the last one) contain exactly 80 characters.

Sample Input

1
2
ab c
def
RR G
GG RGG#

Sample Output

ab fe 

Submit