AC

No attempts yetTime limit1sMemory limit256 MB

Problem

Sunyeong built a small language called AC for manipulating integer arrays. The language has exactly two functions, R and D.

  • R (reverse): reverses the order of the numbers in the array.
  • D (discard): removes the first number of the array. Using D on an empty array raises an error.

Functions can be chained and applied together. For example, RDD reverses the array once and then discards the first two numbers.

Given the initial array and a string of functions to run, write a program that outputs the final array after all functions have been applied.

Input

The first line contains the number of test cases $T$. ($T \le 100$)

Each test case consists of three lines:

  • The first line contains the function string $p$, made up only of the characters R and D, with $1 \le |p| \le 100000$.
  • The second line contains $n$, the number of elements in the array. ($0 \le n \le 100000$)
  • The third line contains the array elements in the form [x1,x2,...,xn]. ($1 \le x_i \le 100$) An empty array is given as [].

Over all test cases, the sum of the lengths of $p$ and the sum of $n$ each do not exceed 700,000.

Output

For each test case, print the resulting array after applying every function, in the form [x1,x2,...,xn] on a single line, with elements separated by commas and no spaces. If an error occurs because D is applied to an empty array at any point, print error instead.