#B3702. Hua Xiaoke's Journey

    ID: 11361 Type: Default 1000ms 256MiB

Hua Xiaoke's Journey

Hua Xiaoke's Journey

Hua Xiaoke is embarking on a journey through the vast campus of Huazhong University of Science and Technology. The map of the campus is divided into ( n ) rows and ( m ) columns, and each position is denoted as ( (i,j) ) where ( 1 \leq i \leq n ) and ( 1 \leq j \leq m ).

At the beginning, Hua Xiaoke starts at position ( (S_x, S_y) ). Each cell ( (i,j) ) of the grid contains a directive that either points to the next cell to visit or instructs to end the journey. When the pointer in the current cell is ( (-1, -1) ), the journey terminates.

Your task is to simulate this travel. Print the coordinates of each position Hua Xiaoke visits sequentially until the journey ends.

It is guaranteed that the journey will end in a finite number of steps.

inputFormat

The first line contains two integers ( n ) and ( m ), representing the number of rows and columns of the grid.

The second line contains two integers ( S_x ) and ( S_y ), the starting coordinates of the journey.

Then follow ( n ) lines, each containing ( 2 \times m ) integers. For each cell ( (i,j) ) in row ( i ), two integers are given representing the pointer in that cell. If the pointer is ( (-1, -1) ), it indicates the end of the journey; otherwise, it gives the next cell's coordinates to visit. The pairs are given in row-major order.

outputFormat

Output the sequence of coordinates visited by Hua Xiaoke. Each visited cell's coordinate ( (i,j) ) should be printed on a separate line, with the row and column numbers separated by a space.

sample

3 3
1 1
1 2 1 3 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
1 1

1 2 1 3

</p>