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.io.*;
import java.util.*;
import java.math.BigInteger; 

public class Main {
    
    
   /*static class sort implements Comparator<int[]>
   {
        public int compare(int[] a,int[] b)
        {
            //if(a[0] == b[0]) return a[1]-b[1];
           return -a[0]+b[0];
        }
   }*/
   public static String[] F(BufferedReader bf) throws Exception
    {
        return (bf.readLine().split(" "));
    }
    static class sort implements Comparator<long[]>
   {
        public int compare(long[] a,long[] b)
        {
            //if(a[0] == b[0]) return a[1]-b[1];
            int i=0;
            if(a[0]>b[0]) i=-1;
            else if(b[0]>a[0]) i=1;
           return i;
        }
   }

   public static void pr(PrintWriter out,Object o)
   {
      
    out.println(o.toString());out.flush();
    
   }
   public static void prW(PrintWriter out,Object o)
   {
      
    out.print(o.toString());out.flush();
    
   }
   public static int intIn(String st)
   {
      return Integer.parseInt(st);
   }
   
   
    
    public static void pr(Object o)
    {
        System.out.println(o.toString());
    }
    public static void prW(Object o)
    {
        System.out.print(o.toString());
    }
    
   
    public static int inInt(String s)
    {
        return Integer.parseInt(s);
    }
    public static long in(String s)
    {
        return Long.parseLong(s);
    }

    
    
    static int[] toIntArray(String[] m) 
    { 
        int[] p=new int[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= inInt(m[o]);
        }
        return p;
    }
    static long[] toLArray(String[] m) 
    { 
       long[] p=new long[m.length];
        for(int o=0;o<m.length;o++)
        {
            p[o]= in(m[o]);
        }
        return p;
    }
    static long max=10000000000000l;static int[] before;static int R;
    static class DSU {
    
    int[] p;int[] sz;int op;int c;;
    int[] last;
    public void G(int n)
    {
        last=new int[n];
        p=new int[n];
        sz=new int[n];c=n;
        op=n;
        for(int h=0;h<n;h++)
        {
            sz[h]=1;p[h]=h;
            last[h]=h;
        }
    }
    public int find(int x)
    {
        int y=x;
        while(x!=p[x]) x=p[x];
        while(y!=p[y])
        {
            int tem=p[y];
            p[y]=x;y=tem;
        }
        return p[y];
    }
    public void union(int a,int b)
    {
        int x,y;
        x=find(a);y=find(b);
        if(x==y) return;
        if(sz[x]>sz[y])
        {
            p[y] = x;
            sz[x]+=sz[y];
            last[x]=Math.max(last[x],last[y]);
        }
        else
        {
            p[x]=y;sz[y]+=sz[x];
            last[y]=Math.max(last[y],last[x]);
        }
        c--;
        
    }}
    static int[][] di={{0,1},{1,0},{0,-1},{-1,0}};

    public static void F(int a,int v,char[][] arr,int n,int m,DSU ds)
    {
        arr[a][v]='#';
        for(int[] d : di)
                        {
                            int z,c;
                            z=a+d[0];
                            c=v+d[1];
                            if(z<0 || c<0 || z>=n || c>=m) continue;
                            if(arr[z][c] == '.')
                            {
                                ds.union(a*m+v,z*m+c);
                                F(z,c,arr,n,m,ds);
                            }
                        }

                        return;




    }
    public static void main (String[] args) throws Exception {
        
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        //PrintWriter out = new PrintWriter(System.out);;;
        
        //int[] map=new int[1000001];
      
        int yy=1;//Integer.parseInt(bf.readLine());
        //sieve(); 
        for(int w=0;w<yy;w++)
        {

            
            
            String[] xlp = bf.readLine().split(" ");;;;
            //String st = bf.readLine();
            int n,k,t,h,x;//boolean bol=false;
           int m;//long a,b,c;
            n=inInt(xlp[0]);m=inInt(xlp[1]);k=inInt(xlp[2]);//t=inInt(xlp[3]);
            char[][] arr=new char[n][m];
            int[][] count = new int[n][m];
            DSU dsu = new DSU();dsu.G(n*m);
            for(int o=0;o<n;o++)
            {
                arr[o]=bf.readLine().toCharArray();
            }
            
            for(int a=0;a<n;a++)
            {
                for(int u=0;u<m;u++)
                {
                    if(arr[a][u]=='*')
                    {
                        for(int[] d : di)
                        {
                            int z,c;
                            z=a+d[0];
                            c=u+d[1];
                            if(z<0 || c<0 || z>=n || c>=m) continue;
                            if(arr[z][c] == '.')
                            {
                                count[z][c]++;
                            }
                        }
                    }
                }

            }

            
            for(int a=0;a<n;a++)
            {
                for(int u=0;u<m;u++)
                {
                    if(arr[a][u] == '.')
                    {
                        int val=(a*m+u);
                        for(int[] d : di)
                        {
                            int z,c;
                            z=a+d[0];
                            c=u+d[1];
                            if(z<0 || c<0 || z>=n || c>=m) continue;
                            if(arr[z][c] == '.')
                            {
                                dsu.union(z*m+c,val);
                            }
                        }
                    }
                }

            }
            int[] res=new int[m*n];
            for(int o=0;o<(m*n);o++)
            {
                int par = dsu.find(o);
                res[par] += (count[o/m][o%m]);
            }
            for(int o=0;o<k;o++)
            {
                int[] tem=toIntArray(F(bf));
                int xc,yc;
                xc=tem[0]-1;yc=tem[1]-1;
                //pr(a1[xc][yc] +" "+a2[xc][yc]+" "+count[xc][yc]);
                int par = dsu.find(xc*m+yc);
                
                pr(res[par]);
            }



            
            

    }
}}


/*
8
5 5
1 1 1 1 1
5 10 20 50 100
10 10
10 10 10 10 10 10 10 10 10 10
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
4 4
4 3 2 1
100 1000 100000 1000000000
10 1
1 1 1 1 1 1 1 1 1 1
999999999
1 10
5
2 3 9 30 566 1337 31337 70775 111111 413413
5 5
1 2 3 4 5
10 40 90 160 250
9 9
5 3 4 2 4 3 5 4 3
4 6 9 10 11 9999 1000000000 1000000000 1000000000
3 3
3 2 3
100 200 400


100663319,201326611,402653189,805306457,1610612741
Kickstart
String rp;
            rp = "Case #"+(w+1)+": "+(n-ans)+" ";
            if(curr == max) rp=rp +"INDEFINITELY";
            else rp = rp+(curr);
static int[][] dir={{0,1},{1,0},{-1,0},{0,-1}};

static class SegmentTreeRMQ 
    { 
    int st[]; 
    int minVal(int x, int y) { 
        return (x > y) ? x : y; 
    } 
  
    
    int getMid(int s, int e) { 
        return s + (e - s) / 2; 
    } 
  
    
    int RMQUtil(int ss, int se, int qs, int qe, int index) 
    { 
        
        if (qs <= ss && qe >= se) 
            return st[index]; 
  
        // If segment of this node is outside the given range 
        if (se < qs || ss > qe) 
            return Integer.MIN_VALUE; 
  
        // If a part of this segment overlaps with the given range 
        int mid = getMid(ss, se); 
        return minVal(RMQUtil(ss, mid, qs, qe, 2 * index + 1), 
                RMQUtil(mid + 1, se, qs, qe, 2 * index + 2)); 
    } 
  
    // Return minimum of elements in range from index qs (query 
    // start) to qe (query end).  It mainly uses RMQUtil() 
    int RMQ(int n, int qs, int qe) 
    { 
        // Check for erroneous input values 
        
  
        return RMQUtil(0, n - 1, qs, qe, 0); 
    } 
  
    // A recursive function that constructs Segment Tree for 
    // array[ss..se]. si is index of current node in segment tree st 
    int constructSTUtil(int arr[], int ss, int se, int si) 
    { 
        // If there is one element in array, store it in current 
        //  node of segment tree and return 
        if (ss == se) { 
            st[si] = arr[ss]; 
            return arr[ss]; 
        } 
  
        // If there are more than one elements, then recur for left and 
        // right subtrees and store the minimum of two values in this node 
        int mid = getMid(ss, se); 
        st[si] = minVal(constructSTUtil(arr, ss, mid, si * 2 + 1), 
                constructSTUtil(arr, mid + 1, se, si * 2 + 2)); 
        return st[si]; 
    } 
  
    
    void con(int arr[]) 
    { 
        // Allocate memory for segment tree 
  
        //Height of segment tree 
        int n = (arr.length);
        int x = (int) (Math.ceil(Math.log(n) / Math.log(2))); 
  
        //Maximum size of segment tree 
        int max_size = 2 * (int) Math.pow(2, x) - 1; 
        st = new int[max_size]; // allocate memory 
  
        // Fill the allocated memory st 
        constructSTUtil(arr, 0, n - 1, 0); 
    }
    }
     static class DSU {
    
    int[] p;int[] sz;int op;int c;;
    int[] last;
    public void G(int n)
    {
        last=new int[n];
        p=new int[n];
        sz=new int[n];c=n;
        op=n;
        for(int h=0;h<n;h++)
        {
            sz[h]=1;p[h]=h;
            last[h]=h;
        }
    }
    public int find(int x)
    {
        int y=x;
        while(x!=p[x]) x=p[x];
        while(y!=p[y])
        {
            int tem=p[y];
            p[y]=x;y=tem;
        }
        return p[y];
    }
    public void union(int a,int b)
    {
        int x,y;
        x=find(a);y=find(b);
        if(x==y) return;
        if(sz[x]>sz[y])
        {
            p[y] = x;
            sz[x]+=sz[y];
            last[x]=Math.max(last[x],last[y]);
        }
        else
        {
            p[x]=y;sz[y]+=sz[x];
            last[y]=Math.max(last[y],last[x]);
        }
        c--;
        
    }}

    static long pow(long x, long y, long p)
      {
        long res = 1; // Initialize result
     
        x = x % p; // Update x if it is more than or
        // equal to p
     
        if (x == 0)
          return 0l; // In case x is divisible by p;
     
        while (y > 0)
        {
     
          // If y is odd, multiply x with result
          if ((y & 1) != 0)
            res = (res * x) % p;
     
          // y must be even now
          y = y >> 1; // y = y/2
          x = (x * x) % p;
        }
        return res;
      }
      static long gcd(long a, long b)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b); 
        }
        static int gcd(int a, int b,int o)
        {
          if (b == 0)
            return a;
          return gcd(b, a % b,o); 
        }


*/