#K64997. Sequence Arrangement
Sequence Arrangement
Sequence Arrangement
You are given several test cases. In each test case, you start with an empty sequence and perform a series of operations to insert numbers either at the front or the back of the sequence. Each operation is given in the form of "ADD_FRONT x" or "ADD_BACK x", where x is an integer.
Your task is to process each test case and output the final sequence after all operations have been applied. The sequence should be printed as space-separated integers.
Operations:
- ADD_FRONT x: Insert the integer x at the beginning of the sequence.
- ADD_BACK x: Append the integer x at the end of the sequence.
Note: Ensure that you read the input from standard input (stdin) and write the output to standard output (stdout).
inputFormat
The first line contains a single integer t ( 1 ≤ t ≤ 100 ), denoting the number of test cases. For each test case:
- The first line contains an integer n ( 1 ≤ n ≤ 103 ) representing the number of operations.
- Each of the following n lines contains an operation in the format "
ADD_FRONT x
" or "ADD_BACK x
", where x is an integer (absolute value within reasonable limits).
outputFormat
For each test case, output a single line containing the final sequence after processing all operations. The numbers must be separated by a single space.
## sample2
3
ADD_BACK 10
ADD_FRONT 5
ADD_BACK 7
2
ADD_FRONT 3
ADD_BACK 9
5 10 7
3 9
</p>