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 javax.swing.*;
import java.io.*;
import java.util.*;
import java.lang.*;
import java.math.*;
import java.text.DecimalFormat;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Main {
    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    //static long MOD = (long) (1e9 + 7);
    static int MOD = 998244353;
    static long MOD2 = MOD * MOD;
    static Reader sc = new Reader();
    static int pInf = Integer.MAX_VALUE;
    static int nInf = Integer.MIN_VALUE;
    static long ded = (long)(1e16);
    public static void main(String[] args) throws Exception  {
        int test = 1;
        //test = sc.nextInt();
        while (test-- > 0) solve();
        out.flush();
        out.close();
    }
    static int[] di = new int[]{0,-1,0,+1};
    static int[] dj = new int[]{-1,0,1,0};
    static char[][] c;
    static int n,m;
    static void solve() throws Exception {
        n = sc.nextInt();
        m = sc.nextInt();
        int k = sc.nextInt();
        c = new char[n][m];
        for(int i = 0 ; i < n; i++){
            c[i] = sc.next().toCharArray();
        }
        col = new int[n][m];
        for(int i = 0 ; i < n; i++){
            Arrays.fill(col[i],-1);
        }
        int colour = 1;
        HashMap<Integer,Integer> C = new HashMap<>();
        for(int i = 0 ; i < n; i++){
            for(int j = 0;j < m; j++){
                if(c[i][j]=='.'&& col[i][j]<0){
                    ans = 0;
                    dfs(i,j,colour);
                    C.put(colour,ans);
                    colour++;
                }
            }
        }
        while(k-->0){
            int x = sc.nextInt()-1;
            int y = sc.nextInt()-1;
            out.println(C.get(col[x][y]));
        }
    }
    static int ans;
    static boolean[][] visited;
    static int[][] col;
    static void dfs(int i,int j,int colour){
        col[i][j] = colour;
        for(int k = 0 ;k < 4; k++){
            int ni = i+di[k];
            int nj = j+dj[k];
            if(e1(ni,nj)){
                ans++;
            }
        }
        for(int k = 0 ;k < 4; k++){
            int ni = i+di[k];
            int nj = j+dj[k];
            if(e2(ni,nj)&&col[ni][nj]<0){
                dfs(ni,nj,colour);
            }
        }
    }
    static boolean e1(int i,int j){
        return i>=0&&i<n&&j>=0&&j<m&&c[i][j]=='*';
    }
    static boolean e2(int i,int j){
        return i>=0&&i<n&&j>=0&&j<m&&c[i][j]=='.';
    }
    public static long mul(long a, long b) {
        return ((a % MOD) * (b % MOD)) % MOD;
    }
    public static long add(long a, long b) {
        return ((a % MOD) + (b % MOD)) % MOD;
    }
    public static long sub(long a, long b) {
        return ((a % MOD) - (b % MOD)) % MOD;
    }
    //Pair Class
    static class Pair implements Comparable<Pair> {
        int x;
        int y;
        int idx;
        public Pair(int x, int y) {
            this.x = x;
            this.y = y;
            this.idx = idx;
        }
        @Override
        public int compareTo(Pair o) {
            if ((this.x == o.x)) {
                return (this.y - o.y);
            }
            return (this.x-o.x);
        }
    }
    static class TPair{
        long x;
        long y;
        public TPair(long x, long y) {
            this.x = x;
            this.y = y;
        }
    }
    //Shuffle Sort
    static final Random random = new Random();
    static void ruffleSort(int[] a) {
        int n = a.length;//shuffle, then sort
        for (int i = 0; i < n; i++) {
            int oi = random.nextInt(n), temp = a[oi];
            a[oi] = a[i];
            a[i] = temp;
        }
        Arrays.sort(a);
    }
    //Brian Kernighans Algorithm
    static long countSetBits(long n) {
        if (n == 0) return 0;
        return 1 + countSetBits(n & (n - 1));
    }
    //Euclidean Algorithm
    static long gcd(long A, long B) {
        if (B == 0) return A;
        return gcd(B, A % B);
    }
    //Modular Exponentiation
    static long fastExpo(long x, long n) {
        if (n == 0) return 1;
        if ((n & 1) == 0) return fastExpo((x * x) % MOD, n / 2) % MOD;
        return ((x % MOD) * fastExpo((x * x) % MOD, (n - 1) / 2)) % MOD;
    }
    //AKS Algorithm
    static boolean isPrime(long n) {
        if (n <= 1) return false;
        if (n <= 3) return true;
        if (n % 2 == 0 || n % 3 == 0) return false;
        for (int i = 5; i <= Math.sqrt(n); i += 6)
            if (n % i == 0 || n % (i + 2) == 0) return false;
        return true;
    }
    public static long modinv(long x) {
        return modpow(x, MOD - 2);
    }
    public static long modpow(long a, long b) {
        if (b == 0) {
            return 1;
        }
        long x = modpow(a, b / 2);
        x = (x * x) % MOD;
        if (b % 2 == 1) {
            return (x * a) % MOD;
        }
        return x;
    }

    public static class Reader {
        BufferedReader br;
        StringTokenizer st;
        //it reads the data about the specified point and divide the data about it ,it is quite fast
        //than using direct

        public Reader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception r) {
                    r.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());//converts string to integer
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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