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.*;
 
public class Main{ 
    
    static boolean ONLINE_JUDGE = false;//change before submit
    static Fast f = new Fast();
    static PrintWriter out = new PrintWriter(System.out); 
    static boolean TEST_CASES = false;

    
    static void solve(int TC_NO) {

       char[][] mat = new char[ri()][ri()];

       int k = ri();

       for(int i = 0; i < mat.length; i++){
          mat[i] = rs().toCharArray();
       }

       
       int[][] map = new int[mat.length][mat[0].length];
       HashMap<Integer,Integer> ans = new HashMap<>();
       int cur = 0;
       boolean visited[][] = new boolean[mat.length][mat[0].length];
       for(int i = 0; i < mat.length; i++){
         for(int j = 0 ; j < mat[i].length; j++) {
            if(mat[i][j]=='.' && !visited[i][j]) {
              ans.put(cur,bfs(i,j,mat,visited,cur,map));
              cur++;
            }
         }
       } 

       while(k-->0){
         int l = ri()-1;
         int r = ri()-1;

         out.println(ans.get(map[l][r]));

       }
      /* WARNING : change [ONLINE_JUDGE = false] before SUBMIT */ 
    }


    static int  bfs(int i1, int j1,char[][] mat, boolean[][] visited, int cur1, int[][] map){
          
          ArrayDeque<Pair> q = new ArrayDeque<>();

          visited[i1][j1] = true;

           map[i1][j1] = cur1;

          //boolean[][] vstar = new boolean[mat.length][mat[0].length];

          q.offer(new Pair(i1,j1));

          int[] dirx = {1,0,-1,0};
          int[] diry = {0,1,0,-1};

          int count = 0;

          while(!q.isEmpty()){
               Pair cur = q.poll();
               int x = cur.first;
               int y = cur.second;
               for(int i = 0; i < 4; i++){
                  if(x+dirx[i]>-1 && x+dirx[i]<mat.length && y+diry[i]>-1 && y+diry[i]<mat[0].length){
                     if(mat[x+dirx[i]][y+diry[i]]=='.' && !visited[x+dirx[i]][y+diry[i]]){
                        map[x+dirx[i]][y+diry[i]] = cur1;
                        q.offer(new Pair(x+dirx[i],y+diry[i]));
                        visited[x+dirx[i]][y+diry[i]] = true;
                     }

                     if(mat[x+dirx[i]][y+diry[i]]=='*'){
                       count++;
                     }
                  }
               }
          }

          return count;


    }

    static class Pair{

        int first;
        int second;

        public Pair(int first, int second){
          this.first = first;
          this.second = second;
        }

    }



    static class MMath {
    
       static int mod(long a, int m) {
          
         a = a - (a/m) * m;
             
         return a < 0? (int)(a+m): (int)a;

       }

       static long mod(long a, long m){
          
           a = a - (a/m) * m;
             
          return a < 0? (a+m): a;
       
       }

       static int madd(long a, long b, int m) {
            
           a = mod(a,m);
           b = mod(b,m);

           return mod(a+b+2l*m,m);

       }

       static int mprod(long a, long b, int m) {

            int result = 0;

            while(a>0){

                if(mod(a,2)==1) 
                  result = madd(result,b,m);

                b = madd(b,b,m);
                a = a>>1; 
            }

            return result;

       }
       
       static int bexpo(int x, int n) {
          
          int result = 1;
          
          while(n>0)
          {
              if(mod(n,2) == 1)
                  result = result * x;
              x = x*x;
              n = n>>1;
          
          }

          return result;
       
       }


       static int mexpo(long x, long n, int m) {
        
          int result = 1;
          x = mod(x,m);
          
          while(n>0) {
              if(mod(n,2) == 1)
                  result = mprod(result,x,m);
              x = mprod(x,x,m);
              n = n>>1;
          }

          return result;

       }


        static long gcd(long a,long b){
           
            while(a!=0 && b!=0){
                 
                 if(a>b) a = mod(a,b);
                 
                 else  b = mod(b,a);
            }

            return a+b;   
        
         } 


        static long lcm(long a, long b) {
                 
            return a / gcd(a,b) * b;

         }
   
    
    }



    


    public static void main(String[] args)throws Exception{

      out = ONLINE_JUDGE? new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))): new PrintWriter(System.out);
      
      if(TEST_CASES){
          
          int t = ri();
          int i = 1;
          while(i<=t){
            solve(i);
            i++;
          }

      }

      else {

        solve(1);
      
      }
      
      out.close();

    }

    static int ri() {

      return f.nextInt();
    
    }

    static long rl() {
 
      return f.nextLong();
    
    }

    static double rd() {

       return f.nextDouble();
    
    }

    static char rc() {
      
       return rs().charAt(0);

    }

    static String rs() {

      return f.next();

    }

    static String rS() {
      
       return f.nextLine();
    
    }

    static int[] ra(int n) {
        
      int[] a = new int[n];
      for(int i = 0;i<n;i++) a[i] = ri();
      return a;
        
    }

    static long[] ral(int n) {
        
      long[] a = new long[n];
      for(int i = 0;i<n;i++) a[i] = rl();
      return a;
        
    }

    static double[] rad(int n) {

      double[] a = new double[n];
      for(int i = 0;i<n;i++) a[i] = rd();
      return a;

    }

    static char[] rac() {

        char[] c = rs().toCharArray();

        return c;

    }
    
    static int[][] rm(int n, int m) {
       
       int[][] mat = new int[n][m];

       for(int i = 0; i < n; i++) mat[i] = ra(m);
       
       return mat;

    }

    static char[][] rmc(int n) {
      
      char[][] cmat = new char[n][];
      
      for(int i = 0; i < n;) cmat[i] = rac();

      return cmat;

    }

    static void sort(int[] a) {

      ArrayList<Integer> list=new ArrayList<>();
      for (int i:a) list.add(i);
      Collections.sort(list);
      for (int i=0; i<a.length; i++) a[i]=list.get(i);

    }
  
    static class Fast{
       public BufferedReader br;
       public StringTokenizer st;
       
       public Fast(){
            try{
                br = ONLINE_JUDGE? (new BufferedReader(new FileReader("input.txt"))):(new BufferedReader(new InputStreamReader(System.in)));
            }
            catch(Exception e){
              throw new RuntimeException(e);
            }
       }
       
       String next(){
            while(st==null || !st.hasMoreTokens()){
                 try{
                      st=new StringTokenizer(br.readLine());
                 }
                 catch(IOException e){
                      throw new RuntimeException(e);
                 }
                 
            }
                 return st.nextToken();
            }
       int nextInt(){
            return Integer.parseInt(next());
       }
   
       long nextLong(){
            return Long.parseLong(next());
       }
   
       double nextDouble(){
            return Double.parseDouble(next());
       }

       String nextLine() 
          { 
              String str = ""; 
              try
              { 
                  str = br.readLine(); 
              } 
              catch (IOException e) 
              { 
                  e.printStackTrace(); 
              } 
              return str; 
          } 
   
    }

    static String gcc(int TC_NO) {

         return "Case #"+TC_NO+": ";

    }

    static boolean isLetter(char c){

      return (64<c && c<91) || (96<c && c<123);
    
    }

}

