You finally trapped Lavutz and his friends in a room (in total there are people). The room is very interesting, as it is split in rows and columns, and for each row and column ( and ) there is a cell which is at units of height (distance in units from the ground). A person can move from cell (, ) to one of the cells (, ), (, ), (, ), (, ) (if that doesn't go out of the boundaries of the room) in exactly second, or they can just stay in cell (, ).
You have a device which can raise the level of the lava, which is initially raised at level , but you don't want to hurt Lavutz or his friends. A person is hurt if the lava is raised at a level greater than the height of the cell where the person is at that moment.
Task
Now, you want to find for each from to what is the minimum time you need to wait such that you can raise the lava to level and nobody gets hurt, or if for any amount of time you will wait, you can't raise the lava to level without hurting anybody.
Input data
On the first line there are integers: , ()- the number of rows and columns and () - the number of people in the room.
On the next lines, there will be () the height of cell (, ). ( and ).
For each of the next lines there will be two integers , ( and ) - the starting position of the people.
Output data
You will print integers. The -th integer is the answer for level .
Constraints and clarifications
- Multiple people can move at the same time.
- Multiple people can be in the same cell at the same time.
- You can raise the lava to level without hurting anybody (each person is at a height of at least ).
Example
stdin
6 5 6
30 14 11 22 16
7 5 6 3 23
20 1 5 2 17
21 1 4 2 6
17 7 3 24 3
26 25 13 14 10
2 2
3 2
4 4
5 5
2 4
4 3
stdout
0 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 4 5 8 8 8 8
Explanation
If you want to raise the lava to level , you need to wait second for the person in cell (, ).
If you want to raise the lava to level , you need to wait seconds for the persons in cell (, ).