logo AlgoBeat OnlineJudge
登录 注册

#216719. [GKS 2019 #C] Wiggle Walk

内存限制:1024 MiB 时间限制:5000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

Banny has just bought a new programmable robot. Eager to test his coding skills, he has placed the robot in a grid of squares with rows (numbered to from north to south) and columns (numbered to from west to east). The square in row and column is denoted .

Initially the robot starts in the square . Banny will give the robot instructions. Each instruction is one of , , or , instructing the robot to move one square north, south, east or west respectively.

If the robot moves into a square that it has been in before, the robot will continue moving in the same direction until it reaches a square that it has not been in before. Banny will never give the robot an instruction that will cause it to move out of the grid.

Can you help Banny determine which square the robot will finish in, after following the instructions?

输入格式

The first line of the input gives the number of test cases, . test cases follow. Each test case starts with a line containing the five integers , , , and , the number of instructions, the number of rows, the number of columns, the robot's starting row and starting column, respectively.

Then, another line follows containing a single string of characters; the -th of these characters is the -th instruction Banny gives the robot (one of , , or , as described above).

输出格式

For each test case, output one line containing Case #x: r c, where x is the test case number (starting from 1), r is the row the robot finishes in and c is the column the robot finishes in.

样例

样例输入 1

3
5 3 6 2 3
EEWNS
4 3 3 1 1
SESE
11 5 8 3 4
NEESSWWNESE

样例输出 1

Case #1: 3 2
Case #2: 3 3
Case #3: 3 7

数据范围与提示

Sample Case #1 corresponds to the top-left diagram, Sample Case #2 corresponds to the top-right diagram and Sample Case #3 corresponds to the lower diagram. In each diagram, the yellow square is the square the robot starts in, while the green square is the square the robot finishes in.

:::align{center} :::

Limits

Memory limit: GB.

.

.

.

.

.

The instructions will not cause the robot to move out of the grid.

Test set 1 (Visible)

.

Test set 2 (Hidden)

.