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.*;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        D solver = new D();
        solver.solve(1, in, out);
        out.close();
    }

    static class D {
        public char[][] matrix;
        public int[][] map;
        public boolean[][] visited;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();

            matrix = new char[n][];
            map = new int[n][m];
            visited = new boolean[n][m];

            for (int i = 0; i < n; ++i) {
                matrix[i] = in.nextCharArray(m);
            }

            HashMap<Pair<Integer, Integer>, Integer> hashMap = new HashMap<>();

            while (k-- > 0) {
                int x = in.nextInt();
                int y = in.nextInt();


                if (map[x - 1][y - 1] == 0) {
                    visitPictures(x - 1, y - 1);
                }

                out.println(map[x - 1][y - 1]);

            }
        }

        public void visitPictures(int x, int y) {
            int count = 0;
            ArrayList<Pair<Integer, Integer>> l = new ArrayList<>();
            Queue<Pair<Integer, Integer>> q = new LinkedList<>();

            Pair<Integer, Integer> pair = new Pair<>(x, y);
            l.add(pair);
            q.add(pair);
            visited[x][y] = true;

            while (!q.isEmpty()) {
                pair = q.poll();
                if (!visited[pair.x][pair.y - 1]) {
                    if (matrix[pair.x][pair.y - 1] == '*') {
                        count++;
                    } else {
                        visited[pair.x][pair.y - 1] = true;
                        Pair<Integer, Integer> p = new Pair<>(pair.x, pair.y - 1);
                        l.add(p);
                        q.offer(p);
                    }
                }
                if (!visited[pair.x][pair.y + 1]) {
                    if (matrix[pair.x][pair.y + 1] == '*') {
                        count++;
                    } else {
                        visited[pair.x][pair.y + 1] = true;
                        Pair<Integer, Integer> p = new Pair<>(pair.x, pair.y + 1);
                        l.add(p);
                        q.offer(p);
                    }
                }
                if (!visited[pair.x - 1][pair.y]) {
                    if (matrix[pair.x - 1][pair.y] == '*') {
                        count++;
                    } else {
                        visited[pair.x - 1][pair.y] = true;
                        Pair<Integer, Integer> p = new Pair<>(pair.x - 1, pair.y);
                        l.add(p);
                        q.offer(p);
                    }
                }
                if (!visited[pair.x + 1][pair.y]) {
                    if (matrix[pair.x + 1][pair.y] == '*') {
                        count++;
                    } else {
                        visited[pair.x + 1][pair.y] = true;
                        Pair<Integer, Integer> p = new Pair<>(pair.x + 1, pair.y);
                        l.add(p);
                        q.offer(p);
                    }
                }
            }

            for (Pair<Integer, Integer> p : l) {
                map[p.x][p.y] = count;
            }
        }

    }

    static class Pair<X, Y> {
        public X x;
        public Y y;

        public Pair(X x, Y y) {
            this.x = x;
            this.y = y;
        }


        public boolean equals(Object o) {
            if (this == o) {
                return true;
            }
            if (o == null || getClass() != o.getClass()) {
                return false;
            }

            Pair<?, ?> pair = (Pair<?, ?>) o;

            if (x != null ? !x.equals(pair.x) : pair.x != null) {
                return false;
            }
            return y != null ? y.equals(pair.y) : pair.y == null;
        }


        public int hashCode() {
            int result = x != null ? x.hashCode() : 0;
            result = 31 * result + (y != null ? y.hashCode() : 0);
            return result;
        }

    }

    static class InputReader {
        private final byte[] buffer = new byte[8192];
        private InputStream in;
        private int pos = 0;
        private int len = 0;

        public InputReader(InputStream stream) {
            in = stream;
        }

        private static boolean isDigit(int c) {
            return c >= '0' && c <= '9';
        }

        private static boolean isPrintable(int c) {
            return c >= 33 && c <= 126;
        }

        public char nextChar() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }

            int b = readByte();
            while (b != -1 && !isPrintable(b)) {
                b = readByte();
            }

            return (char) b;
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long num = 0;
            boolean neg = false;
            int b = readByte();
            if (!(isDigit(b) || b == '-')) {
                throw new NumberFormatException();
            } else {
                if (b == '-') {
                    neg = true;
                } else {
                    num += b - '0';
                }

                while ((b = readByte()) != -1 && isDigit(b)) {
                    num *= 10;
                    num += b - '0';
                }
            }
            return neg ? -num : num;
        }

        public char[] nextCharArray(int n) {
            char[] chars = new char[n];
            for (int i = 0; i < n; ++i) {
                chars[i] = nextChar();
            }
            return chars;
        }

        private boolean hasNext() {
            while (hasNextByte() && !isPrintable(buffer[pos])) {
                pos++;
            }
            return hasNextByte();
        }

        private boolean hasNextByte() {
            if (pos >= len) {
                pos = 0;
                try {
                    len = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (len <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[pos++];
            } else {
                return -1;
            }
        }

    }

    static class OutputWriter {
        private PrintWriter out;

        public OutputWriter(OutputStream stream) {
            out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream)));
        }

        public OutputWriter(Writer writer) {
            out = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; ++i) {
                if (i > 0) {
                    out.print(' ');
                }
                out.print(objects[i]);
            }
        }

        public void println(Object... objects) {
            print(objects);
            out.println();
        }

        public void close() {
            out.close();
        }

    }
}

