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
/**
 *
 * @author meashish
 */
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

    InputReader in;
    Printer out;

    private void start() throws Exception {
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();

        int ans[][] = new int[n][m];
        int ones[][] = new int[n][m];
        boolean visited[][] = new boolean[n][m];
        boolean viz[][] = new boolean[n][m];
        
        String[] grid = new String[n];
        for (int i = 0; i < n; i++) {
            grid[i] = in.next();
        }
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (grid[i].charAt(j) == '*') {
                    int x = i + 1, y = j;
                    
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*') {
                        ones[x][y] += 1;
                    }
                    
                    x = i; y = j + 1;
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*') {
                        ones[x][y] += 1;
                    }
                    
                    x = i - 1; y = j;
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*') {
                        ones[x][y] += 1;
                    }
                    
                    x = i; y = j - 1;
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*') {
                        ones[x][y] += 1;
                    }
                }
            }
        }

        ArrayList<Pair> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (ans[i][j] > 0 || viz[i][j] || grid[i].charAt(j) == '*') {
                    continue;
                }
                
                Queue<Integer> q1 = new LinkedList();
                Queue<Integer> q2 = new LinkedList();
                
                list.clear();

                int sum = 0;
                //q1.add(new Pair(i, j));
                q1.add(i);
                q2.add(j);
                visited[i][j] = true;
                
                while (!q1.isEmpty()) {
                    //Pair pair = q1.poll();
                    int key = q1.poll();
                    int value = q2.poll();
                    
                    sum += ones[key][value];
                    
                    int x = key + 1, y = value;
                    
                    //Pair pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key; y = value + 1;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key - 1; y = value;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key; y = value - 1;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                }
                
                ans[i][j] = sum;
                
                for (Pair pair: list) {
                    visited[pair.key][pair.value] = false;
                }
                
                /*for (int p = 0; p < n; p++) {
                    for (int q = 0; q < m; q++) {
                        visited[p][q] = false;
                    }
                }*/

                list.clear();
                //queue = new LinkedList<>();
                q1.add(i);
                q2.add(j);
                visited[i][j] = true;
                
                while (!q1.isEmpty()) {
                    int key = q1.poll();
                    int value = q2.poll();
                    ans[key][value] = ans[i][j];
                    viz[key][value] = true;
                    
                    int x = key + 1, y = value;
                    
                    //Pair pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key; y = value + 1;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key - 1; y = value;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                    
                    x = key; y = value - 1;
                    //pair2 = new Pair(x, y);
                    if (x < n && x >= 0 && y < m && y >= 0 && grid[x].charAt(y) != '*' && !visited[x][y]) {
                        q1.add(x);
                        q2.add(y);
                        visited[x][y] = true;
                        list.add(new Pair(x, y));
                    }
                }
                
                for (Pair pair: list) {
                    visited[pair.key][pair.value] = false;
                }
            }
        }
        
        /*for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(ones[i][j] + " ");
            }
            out.println();
        }
        
        out.println();
        
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                out.print(ans[i][j] + " ");
            }
            out.println();
        }
        
        out.println();
        */
        while (k-- > 0) {
            int x = in.nextInt();
            int y = in.nextInt();
            
            out.println(ans[x - 1][y - 1]);
        }
        
        out.flush();
    }

    public static void main(String[] args) throws Exception {
        InputReader in;
        PrintStream out;

        //in = new InputReader(new FileInputStream(new File("C-small-attempt1.in")));
        //out = new PrintStream("out.txt");
        in = new InputReader(System.in);
        out = System.out;

        Main main = new Main();

        main.in = in;
        main.out = new Printer(out);

        main.start();
    }

    private void check(HashSet<Pair> set, boolean[][] visited, int x, int y, Pair pair2) throws Exception {
        boolean b1 = set.contains(pair2);
        boolean b2 = visited[x][y];
        
        if (b1 != b2) {
            throw new Exception("");
        }
    }

    private static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return nextString();
        }

        public interface SpaceCharFilter {

            public boolean isSpaceChar(int ch);
        }
    }

    private static class Printer {

        PrintStream out;
        StringBuilder buffer = new StringBuilder();
        boolean autoFlush;

        public Printer(PrintStream out) {
            this.out = out;
        }

        public Printer(PrintStream out, boolean autoFlush) {
            this.out = out;
            this.autoFlush = autoFlush;
        }

        public void println() {
            buffer.append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void println(int n) {
            println(Integer.toString(n));
        }

        public void println(long n) {
            println(Long.toString(n));
        }

        public void println(double n) {
            println(Double.toString(n));
        }

        public void println(float n) {
            println(Float.toString(n));
        }

        public void println(boolean n) {
            println(Boolean.toString(n));
        }

        public void println(char n) {
            println(Character.toString(n));
        }

        public void println(byte n) {
            println(Byte.toString(n));
        }

        public void println(short n) {
            println(Short.toString(n));
        }

        public void println(Object o) {
            println(o.toString());
        }

        public void println(String s) {
            buffer.append(s).append("\n");

            if (autoFlush) {
                flush();
            }
        }

        public void print(String s) {
            buffer.append(s);

            if (autoFlush) {
                flush();
            }
        }

        public void flush() {
            try {
                BufferedWriter log = new BufferedWriter(new OutputStreamWriter(out));
                log.write(buffer.toString());

                log.flush();
                buffer = new StringBuilder();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private class Pair implements Serializable {

        private int key;

        public int getKey() {
            return key;
        }
        
        private int value;

        public int getValue() {
            return value;
        }

        public Pair(int key, int value) {
            this.key = key;
            this.value = value;
        }

        @Override
        public String toString() {
            return key + "=" + value;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Pair other = (Pair) obj;
            if (this.key != other.key) {
                return false;
            }
            if (this.value != other.value) {
                return false;
            }
            return true;
        }

        @Override
        public int hashCode() {
            return key + 13 * value;
        }
    }
}