RoboFest
You take part in robotechnical contest "RoboFest". Your robot must pass all intermediate checkpoints and return to start. You have the map of the area, and you want to find optimal route for your robot. The map is a matrix with N×M cells. Robot can move from cell to another cell if the cells have common side. Each cell has an integer number - the time robot will take to arrive to this cell (to get to this cell from a neighbor one). Also you have the list of coordinates of intermediate checkpoints and of the start/finish. You can pass the checkpoints in any order.
Input
First line contains integer numbers N and M (1 ≤ N, M ≤ 40). Next N lines contain M integer numbers each, separated by spaces - the time values, required to arrive to the corresponding cells. Next line contains K - the quantity of intermediate checkpoints (1 ≤ K ≤ 15). Next K lines contain two integer numbers each (X_i and Y_i), separated by spaces - the coordinates of corresponding checkpoints (0 ≤ X_i < N, 0 ≤ Y_i < M). Next line contains two integer numbers (X and Y), separated by spaces - the coordinates of the start/finish (0 ≤ X < N, 0 ≤ Y < M). X-coordinates are zero-indexed rows, numerated from up to down. Y-coordinates are zero-indexed columns, numerated from left to right.
Output
Output the minimal time, robot will take to finish the race.