There is a NXM grid and every cell of grid has a person or has an obstacle, now a person at Aij can move to A(i−1)j, A(i+1)j, Ai(j−1) and Ai(j+1), given that the box is in grid and it does not have an obstacle.
Now, you are given Q queries, In each query you are given two integers L and R. You need to find how many person can come to cell ALR.
INPUT
First line of input contains two integers N and M, N line follows each containing M space separated integers, elements of grid. Next line contain a single integer Q number of queries. Q lines follow each containing two space separated integer L and R.
OUTPUT
For each query print number of person who can visit that cell of grid.
CONSTRAINTS