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 × m cells. Each cell is either empty or impassable. Empty cells are marked with '.', impassable cells are marked with '*'. Every two adjacent cells of different types (one empty and one impassable) are divided by a wall containing one picture.

At the beginning Igor is in some empty cell. At every moment he can move to any empty cell that 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 only if he is in the cell adjacent to the wall with this picture. Igor have a lot of time, so he will 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, 100 000)) — 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 that all border cells are impassable, so Igor can't go out from the museum.

Each of the last k lines contains two integers x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) — the row and the column of one of Igor's starting positions respectively. Rows are numbered from top to bottom, columns — from left to right. It is guaranteed that all starting positions are empty cells.

Output

Print k integers — the maximum number of pictures, that Igor can see if he starts in corresponding position.

Examples

Input

5 6 3
******
*..*.*
******
*....*
******
2 2
2 5
4 3


Output

6
4
10


Input

4 4 1
****
*..*
*.**
****
3 2


Output

8
import java.util.*;
import java.io.*;

//DONT FORGET TO CHANGE CLASS NAME!
public class IgorInTheMuseum {
    /*
    With a 1000x1000 = 10^6 grid to search and up to 100,000 tests, 
        there is no way we can search every time
    Instead we can do an initial round of searching, evaluating every spot as we go
        and then just do every solution in O(1)
    The initial round takes 2*10^6 comps max

    How2Do:
    For every cell in the grid:
        if impassible or visited:
            pass
        numPaintings = 0
        q = Queue()
        s = Stack()
        q.add(cell)
        while q has elements:
            c = q.poll()
            s.push(c)
            for neighbor of c:
                if neighbor is impassible:
                    numPaintings+=1
                elif neighbor is not visited:
                    q.add(neighbor)
                c is now visited
        while s has elements:
            c = s.pop()
            visible[c] = numPaintings

    for query:
        print(visible[query])
    */


    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in); //replace with System.in
        PrintWriter writer = new PrintWriter(System.out);
        //Declare our variables
        StringTokenizer st;
        boolean [][] map, visited;
        int[][] visible;
        LinkedList<Coordinate> q;
        Stack<Coordinate> stack;
        int m, n, numQueries, i, k, numPaintings, a, b;
        String[] row;
        Coordinate c;

        //initialize all variables
        st = new StringTokenizer(sc.nextLine());
        m = Integer.parseInt(st.nextToken());
        n = Integer.parseInt(st.nextToken());
        numQueries = Integer.parseInt(st.nextToken());
        map = new boolean[m][n];
        visited = new boolean[m][n];
        visible = new int[m][n];
        // create our map of the museum
        for(i=0;i<m;i++){
            row = sc.nextLine().split("");
            for(k=0;k<n;k++){
                if(row[k].equals(".")){
                    map[i][k] = true; // true if there is a spot there, false if a wall
                }
            }
        }


        // setup the visible array
        for(i=0;i<m;i++){
            for(k=0;k<n;k++){
                if(visited[i][k] || !map[i][k]){continue;}
                numPaintings = 0;
                q = new LinkedList<Coordinate>();
                stack = new Stack<Coordinate>();
                q.add(new Coordinate(i, k));
                visited[i][k] = true;
                // perform the BFS
                while(!q.isEmpty()){
                    c = q.poll();
                    stack.push(c);
                    for(a=-1;a<=1;a++){
                        for(b=-1;b<=1;b++){
                            if( outOfBounds(c.x+a, c.y+b, m, n) ){continue;} //cannot go outside of array
                            if(a == 0 && b == 0){continue;} // we are not neighbors with self
                            if(a!=0 && b!=0){continue;} // we are checking immedeite neighbors, no diagnols
                            if(!map[c.x+a][c.y+b]){numPaintings += 1;}
                            else if (!visited[c.x+a][c.y+b]){
                                q.add(new Coordinate(c.x+a, c.y+b));
                                visited[c.x+a][c.y+b] = true;
                            }
                        }
                    }
                }
                // go through and fill in the visible paintings for all searched
                while(!stack.isEmpty()){
                    c = stack.pop();
                    visible[c.x][c.y] = numPaintings;
                }
            }
        }

        for(i=0; i<numQueries;i++){
            st = new StringTokenizer(sc.nextLine());
            a = Integer.parseInt(st.nextToken()) - 1;
            b = Integer.parseInt(st.nextToken()) - 1;
            writer.println(visible[a][b]);

        }







        writer.close(); 
        sc.close();

    }

    
static class Coordinate {
        int x, y;

        public Coordinate(int x_, int y_) {
            x = x_;
            y = y_;
        }

        @Override
        public String toString() {
            return "(" + x + "," + y + ")";
        }
        public boolean equals(Coordinate c1, Coordinate c2){
            return c1.x==c2.x && c1.y==c2.y;
        }

    }


static boolean outOfBounds(int valueX, int valueY, int boundX, int boundY){
    return valueX<0 || valueX>=boundX || valueY<0 || valueY>=boundY;

}



    }//Class Close Bracket
