Change

Time limit: 2 seconds

Problem

We want a program which works as follows.

Your task is to write a program that works as above.

Input

The input starts with an integer k <= 1,000 specifying the number of test cases. Each test case starts with an integer n <= 100,000, which is the number of commands for a machine. Then n lines follow with one command on each line. The "end" command will only appear once at the end.

Output

For each test case, print the string s on a single line.

Sample Input

2
5
append x
append y
reverse
append x
end
7
append a
append x
reverse
append y
append y
reverse
end

Sample Output

yxx
yyax

Author

Chan Ho Leung