Mountaineers
The Chilean Andes have become increasingly popular as a destination for backpacking and hiking. Many parts of the Andes are quite remote and thus dangerous. Because of this, the Ministry of Tourism wants to help travelers plan their trips. In particular, the travelers need to know how high they will have to climb during their journey, as this information will help them decide which equipment they need to bring. The Ministry has tasked you to provide the aspiring mountaineers with this data.
You are given a topographic map of a part of the Andes, represented as a two-dimensional grid of height values, as well as the list of origins and destinations. Mountaineers can move from each grid cell to any of the four adjacent cells. For each mountaineer find the minimal height that they must be able to reach in order to complete their journey.
Input
The first line contains three integers and , where is the number of rows, is the number of columns, and is the number of mountaineers.
Each of the next lines contains integers , the height values in the map;
Each of the next lines contains four integers , describing a mountaineer who wants to trek from to .
The top left cell of the grid has coordinates and the bottom right cell has coordinates .
Output
Output integers, the minimal height for each mountaineer, in the same order as in the input.