Back

Conveyor Belts

Worth 4 point(s) - Runtime Limit: 1 seconds

Introduction

In pursuit of a more productive factory, assembly lines were created so production could be divided into simple steps. Of course, conveyor belts are used to automatically transport intermediate products throughout the factory. However, many assemblies are non-linear, resulting in complicated conveyor systems. The manager of one such assembly line has asked you to write a program to find the endpoint of a product given a map of the conveyor system and the product’s starting point. The map is an array of cells with n rows by m columns. Each cell is represented by one of the characters that follow:

The first period that the product moves onto is considered the endpoint of product.
Note that the top-leftmost cell is at (1, 1) and the bottom-rightmost cell is at (n, m). Assume that the product will never be carried off the map and that there will never be a “loop” in the conveyor system.

Input:
The first line contains an integer N, denoting the number of test cases. Each test case begins with 4 integers, n, m, r, c, respectively, denoting an n by m map and a starting point of row r and column c. The next n lines contain m characters each, denoting the conveyor map with the notation above.

Output:
For each test case, output a line containing the row and column of the product’s endpoint with a space in between.

Sample Input

1
5 5 1 1
v.v>v
>>>^v
v.v<<
>.v.<
^^.^^

Sample Output

5 3