Http://blog.csdn.net/snowy_smile/article/details/49924965D. Igor in the Museumtime limit per test 1 secondmemory limit per test, Megabytesinput standard InputOutput standard OUTPU T
Igor is in the museum and he wants to see as many pictures as possible.
Museum can be represented as a rectangular field of n x m cells. Each cell is either empty or impassable. Empty cells is marked with '. ', impassable cells is marked with '* '. Every adjacent cells of different types (one empty and one impassable) is divided by a wall containing one picture.
At the beginning Igor are in some empty cell. At every moment he can move to any empty cell, which share a side with the current one.
For several starting positions you should calculate the maximum number of pictures that Igor can see. Igor is able to see the picture of the only if he was in the cell adjacent to the wall with the this picture. Igor has a lot of time, so he'll examine every picture he can see.
Input
First line of the input contains three integers n, m and k (3≤ n, m ≤ 1000, 1≤ k ≤ min( n· M)-the Museum dimensions and the number of starting positions to process.
Each of the next n lines contains m symbols '. ', '* '-the description of the museum. It is guaranteed this all border cells be impassable, so Igor can ' t go out from the museum.
Each of the last K lines contains, integers x and y (1≤ x ≤ n, 1≤ y ≤ m)-the row and the column of one of Igor ' s starting positions respectively. Rows is numbered from the top to the bottom, Columns-from left to right. It is guaranteed, all starting positions is empty cells.
Output
Print k integers-the maximum number of pictures, that Igor can see if he starts in corresponding position.
Sample Test (s) input
5 6 3*******. *.********....*******2 22 54 3
Output
6410
Input
4 4 1*****. **.******3 2
Output
8
Educational codeforces Round 1D "Dfs seeking Unicom block"