The Rocky Horror Picture Show

0.7 If you’re staying at Dr. Frank N. Furter’s place, you’d better watch your step! The moment the music kicks in, just look at the squares on the floor, join the other guests, follow the dance moves, and…let’s do the Time Warp again!

But hey, there are so many ways you can literally get warped and be sent back to Transsexual Transylvania:

0.3

Given how all guests are at the start of the dance, can you tell how many of you would remain on the dance floor if the music went on forever?

Input

Input begins with the number of cases n0n \ge 0. For every case, we have the dimensions WW and HH of the room, followed by the number of people PP, followed by PP triplets xix_i, yiy_i, bib_i with the position of the dancer and the direction he or she is facing. Follow the number of steps SS in the dance, followed by SS characters $s_i \in \{`\texttt{\small F}', `\texttt{\small R}', `\texttt{\small B}', `\texttt{\small L}'\}$ denoting a step forward, right, backward, or left, respectively.

Assume that WW and HH are between 1 and 10610^6, 1P1041 \le P \le 10^4, 1xiW1 \le x_i \le W, 1yiH1 \le y_i \le H, $b_i \in \{`\texttt{\small N}', `\texttt{\small E}', `\texttt{\small S}', `\texttt{\small W}'\}$, 1S1041 \le S \le 10^4, and that no two dancers will start at the same position.

Output

For each case, print the number of people that will be dancing indefinitely without ever being warped.

Problem information

Author: Edgar Gonzàlez

Generation: 2026-01-25T10:16:39.523Z

© Jutge.org, 2006–2026.
https://jutge.org