Shortest Path Queries

아직 제출이 없습니다시간 제한5초메모리 제한512 MB

문제

You are given a W×HW \times H grid. Each cell contains an integer. The top-left cell is called (1,1)(1, 1), and the bottom-right cell is called (W,H)(W, H).

A path from a cell SS to a cell TT is a sequence of cells such that the first cell in the sequence is SS, the last cell in the sequence is TT, and any two consecutive cells in the sequence share an edge. The cost of a path is defined as the sum of costs of all cells in the path.

You are given the integers written on the grid, and also QQ pairs of cells (SX_i,SY_i)(\mathit{SX}\_i, \mathit{SY}\_i), (TX_i,TY_i)(\mathit{TX}\_i, \mathit{TY}\_i). For each pair, compute the minimum cost of the path from the cell (SX_i,SY_i)(\mathit{SX}\_i, \mathit{SY}\_i) to the cell (TX_i,TY_i)(\mathit{TX}\_i, \mathit{TY}\_i).

입력

On the first line, you are given three integers WW, HH, and QQ (1W101 \le W \le 10, 2H1042 \le H \le 10^4, 1Q1051 \le Q \le 10^5).

On the next HH lines, you are given the information about the grid. The xx-th number in the yy-th of these lines, A_x,yA\_{x,y}, is the integer written in the cell (x,y)(x, y) (0A_x,y1090 \le A\_{x,y} \le 10^9).

On the next QQ lines, you are given pairs of cells (SX_i,SY_i)(\mathit{SX}\_i, \mathit{SY}\_i), (TX_i,TY_i)(\mathit{TX}\_i, \mathit{TY}\_i) (1SX_i,TX_iW1 \le \mathit{SX}\_i, \mathit{TX}\_i \le W, 1SY_i,TY_iH1 \le \mathit{SY}\_i, \mathit{TY}\_i \le H, (SX_i,SY_i)(TX_i,TY_i)(\mathit{SX}\_i, \mathit{SY}\_i) \ne (\mathit{TX}\_i, \mathit{TY}\_i)).

출력

Print QQ lines. On the ii-th line, print the answer for the pair (SX_i,SY_i)(\mathit{SX}\_i, \mathit{SY}\_i) and (TX_i,TY_i)(\mathit{TX}\_i, \mathit{TY}\_i).