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.awt.*;
import java.awt.geom.Line2D;
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Map.Entry;

public class Main implements Runnable {
    
    String fileInName = "joseph";
    boolean file = false;
    int maxn = (int)1e3+100;
    int mod = (int)1e9+7;
    int inf = (int)1e9;
    int n,m,k;
    char c[][] = new char [maxn][maxn];
    int dp[][] = new int [maxn][maxn];
    boolean used[][] = new boolean[maxn][maxn];
    
    void solve() throws Exception {
        
        n = in.nextInt();
        m = in.nextInt();
        k = in.nextInt();
        
        for (int i=1; i<=n; i++) {
            String s = in.nextToken();
            for (int j=0; j<s.length(); j++) {
                c[i][j+1] = s.charAt(j);
            }
        }
        
        for (int i=0; i<=n+1; i++) {
            Arrays.fill(dp[i], -1);
        }
        
        for (int i=1; i<=k; i++) {
            int l = in.nextInt();
            int r = in.nextInt();
            if (dp[l][r]!=-1) out.println(dp[l][r]);
            else {
                int howMany = bfs(l,r);
                bfsUpdate(l,r, howMany);
                out.println(dp[l][r]);              
            }
        }
        
    }   
    
    private void bfsUpdate(int xx, int yy, int howMany) {
        
        Deque<Pair> q = new ArrayDeque<Pair>();
        q.add(new Pair (xx, yy));
        dp[xx][yy] = howMany;
        int dx[] = {0,0,1,-1};
        int dy[] = {-1,1,0,0};
        
        while (!q.isEmpty()) {
            Pair p = q.pop();
            int x = p.x;
            int y = p.y;
            for (int i=0; i<dx.length; i++) {
                int x1 = x+dx[i];
                int y1 = y+dy[i];
                if (check(x1,y1, false)) {
                    q.add(new Pair (x1,y1));
                    dp[x1][y1] = howMany;
                }
            }
        }
    }

    private int bfs(int xx, int yy) {
        
        Deque<Pair> q = new ArrayDeque<Pair>();
        q.add(new Pair (xx, yy));
        used[xx][yy] = true;
        
        int dx[] = {0,0,1,-1};
        int dy[] = {-1,1,0,0};
        int sum = 0;
        
        while (!q.isEmpty()) {
            Pair p = q.pop();
            int x = p.x;
            int y = p.y;
            for (int i=0; i<dx.length; i++) {
                int x1 = x+dx[i];
                int y1 = y+dy[i];
                if (check(x1,y1, true)) {
                    q.add(new Pair (x1,y1));
                    used[x1][y1] = true;
                } else {
                    if (c[x1][y1]=='*') sum++;
                }
            }
        }
        
        return sum;
    }

    private boolean check(int x, int y, boolean type) {
        if (type) return (x>=1 && x<=n && y>=1 && y<=m && c[x][y]=='.' && !used[x][y]);
        else return (x>=1 && x<=n && y>=1 && y<=m && c[x][y]=='.' && dp[x][y]==-1);
    }

    class Pair implements Comparable<Pair>{
        int x,y; 
        
        public Pair (int x, int y) {
            this.x = x;
            this.y = y;
        }

//      @Override
//      public int compareTo(Pair p) {
//          if (x>p.x) return 1;
//          else if (x==p.x) {
//              if (y>p.y) return 1;
//              else if (y==p.y) return 0;
//              else return -1;
//          } else {
//              return -1;
//          }
//      }
        
        @Override
        public int compareTo(Pair p) {
            if (Math.atan2(-y, x) > Math.atan2(-p.y, p.x)) {
                return 1;
            } else if (Math.atan2(-y, x) == Math.atan2(-p.y, p.x)) {
                return 0;
            } else {
                return -1;
            }
        }
    }
    
    static Throwable throwable;
    public static void main (String [] args) throws Throwable {
        Thread thread = new Thread(null, new Main(), "", (1 << 26));
        thread.start();
        thread.join();
        thread.run();
        if (throwable != null)
            throw throwable;
    }
    
    FastReader in;
    PrintWriter out;

    public void run() {
        try {
            if (file) {
                in = new FastReader(new BufferedReader(new FileReader(fileInName+".in")));
                out = new PrintWriter (fileInName + ".out");
            } else {
                in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(System.out);
            }
            
            solve();
        } catch(Exception e) {
            throwable = e;
        } finally {
            out.close();
        }

    }
}

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }
    
    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        if (!tk.hasMoreTokens()) return nextToken();
        else 
            return tk.nextToken();
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}