We want a program which works as follows.
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.
For each test case, print the string s on a single line.
2 5 append x append y reverse append x end 7 append a append x reverse append y append y reverse end