QOJ.ac

QOJ

Time Limit: 8 s Memory Limit: 1024 MB Total points: 100

#15515. Hoppers

統計

Joshua has built a factory in minecraft, which consists of a grid where each cell contains a so-called hopper. A hopper can store an item within it, and points towards another hopper that is located either directly above, below, to the left or to the right of it. Once per second, each hopper pushes the item they have inside themselves to the hopper they are pointing at if they have an item inside. Sometimes this can lead to a hopper having more than one item inside simultaneously. This obviously doesn’t work, as all the items pushed into the hopper that second are destroyed.

Joshua wants a stable factory without a lot of collisions. He therefore gives you a proposal on how the items should be placed and how the factory should look, and now wants to know for each item if it will collide or keep cycling endlessly in the factory. For all the items that collide, he also wants to know where the collision occurred so he can then update his design. Write a program to help him!

problem_15515_1.png problem_15515_2.png

Figure 1: The factory in sample 1 before it has started and after one second. Note that three items collided in the middle square.

Input

The first line contains the integers $R, C$ $R, C$ ($2 \le R \cdot C \le 10^6$), $N$ ($1 \le N \le 10^5$), the number of rows and columns of the grid, and the number of items in the proposal.

The following $R$ rows describe the layout of the factory. Each of these rows consists of a string of $C$ characters. Each character in the grid indicates the direction the hopper in that square is pointing towards. The characters will either be ’v’ (down), ’<’ (left), ’^’ (up), or ’>’ (right). It is guaranteed that each hopper points to another hopper.

Then follows $N$ rows, each containing two integers $P_r$ ($0 \leq P_r \leq R-1$) and $P_c$ ($0 \leq P_c \leq C-1$), the row and column where the $i$th item starts. No hopper initially contains two or more items.

Output

For each item in the same order as in the input, print a line with “cycle” if the item never collides with anything, or “$r$ $c$” if it collides with something in the hopper at row $r$ and column $c$ ($0$-indexed).

Example

Input

3 3 5
vvv
>v<
>>^
0 1
1 0
1 2
2 0
2 2

Output

1 1
1 1
1 1
cycle
cycle

Input

1 2 2
><
0 0
0 1

Output

cycle
cycle

Input

3 3 3
vvv
v<<
>^^
0 0
0 2
2 2

Output

cycle
1 2
1 2

Scoring

Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.

Group Points Constraints
$1$ $10$ $R \cdot C \le 1000, N \le 1000$
$2$ $35$ $N \le 1000$
$3$ $15$ If a hopper is part of a cycle, then at most one other hopper points towards it.
$4$ $25$ No hopper points upwards.
$5$ $15$ No additional constraints.
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.