1675Word Process Machine

1675   Word Process Machine

题目描述

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.

输入格式:

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.

输出格式:

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.

输入样例 复制
1

2
ab c
def
RR G
GG RGG#

输出样例 复制
ab fe 

说明

2
2
通过提交
时空限制2000ms/64mb
题目来源
评测方式在线评测
题目类型
难        度