Олимпиадный тренинг

Задача 18789. Going for gold - 2


One day the king decided to reward one of his wise men for a good job. He led him into a rectangular room measuring NxM, in each cell of which lay several kilograms of gold. The king allowed the sage to go around several cells (moving from the cell where the sage is now to one of the four neighboring cells) and collect all the gold that gets in his way.
A sage is allowed to pass over the same square more than once. At the same time, he takes gold from it  only once - when he passes through the cell for the first time.

You are given the route of the sage. It is required to determine how many kilograms of gold he collected.

Input
The input data contains the plan of the room and the route of the sage. First, the number of rows N, then the number of columns M (1<=N<=20,1<=M<=20).
Then N lines are written with M numbers in each - the number of kilograms of gold that lies in this cell (a number from 0 to 50).
Next, the number X is written - how many cells the sage walked around. Next, the coordinates of these cells are recorded (the coordinates of a cell are two numbers: the first determines the row number, the second determines the column number, the upper left cell on the plan has coordinates (1,1), the lower right one - (N,M)). 
The number of cells passed by the sage does not exceed 10000.

Imprint
In the output file, output the number of kilograms of gold that the sage collected.
 
Examples
# Input Output
1
3 4
1 2 3 4
5 6 7 8
9 10 11 12
9
1 1
2 1
2 2
2 3
1 3
1 2
1 1
1 2
2 2
24