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

public class Solution {

    public static void main(String[] args) throws Exception {
        IOFast in = new IOFast();
        PrintWriter out = new PrintWriter(System.out);
        
        int n = in.nextInt();
        int m = in.nextInt();
        int k = in.nextInt();
        char[][] a = new char[n][m];
        int[][] ans = new int[n][m];
        int[][] res = new int[n][m];
        boolean[][] vis = new boolean[n][m];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLine();
            for (int j = 0; j < m; j++) {
                ans[i][j] = 0;
                res[i][j] = 0;
                vis[i][j] = false;
            }
        }
        int[] dx = { -1, 0, 1, 0 };
        int[] dy = { 0, -1, 0, 1 };
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (a[i][j] != '.') {
                    continue;
                }
                for (int dir = 0; dir < 4; dir++) {
                    if (i + dx[dir] < 0 || i + dx[dir] >= n) {
                        continue;
                    }
                    if (j + dy[dir] < 0 || j + dy[dir] >= m) {
                        continue;
                    }
                    if (a[i + dx[dir]][j + dy[dir]] == '*') {
                        ans[i][j]++;
                    }
                }
            }
        }
        
        Deque<Integer> q = new ArrayDeque<Integer>();
        Deque<Integer> q2 = new ArrayDeque<Integer>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (vis[i][j] || a[i][j] != '.') {
                    continue;
                }
                int cur = 0;
                q.push(i * m + j);
                q2.push(i * m + j);
                while (!q.isEmpty()) {
                    int v = q.poll();
                    int vx = v / m;
                    int vy = v % m;
                    if (vis[vx][vy]) {
                        continue;
                    }
                    vis[vx][vy] = true;
                    cur += ans[vx][vy];
                    for (int dir = 0; dir < 4; dir++) {
                        if (vx + dx[dir] < 0 || vx + dx[dir] >= n) {
                            continue;
                        }
                        if (vy + dy[dir] < 0 || vy + dy[dir] >= m) {
                            continue;
                        }
                        if (a[vx + dx[dir]][vy + dy[dir]] == '*') {
                            continue;
                        }
                        q.push((vx + dx[dir]) * m + vy + dy[dir]);
                        q2.push((vx + dx[dir]) * m + vy + dy[dir]);
                    }
                }
                while (!q2.isEmpty()) {
                    int v = q2.poll();
                    int vx = v / m;
                    int vy = v % m;
                    res[vx][vy] = cur;
                }
            }
        }
        for (int i = 0; i < k; i++) {
            int p1 = in.nextInt();
            int p2 = in.nextInt();
            p1--;
            p2--;
            out.println(res[p1][p2]);
        }
        
        out.flush();
        out.close();
    }
    
    public static class Point implements Comparable<Point> {
        int x, y;
        
        public Point(int _x, int _y) {
            x = _x;
            y = _y;
        }
        
        public int compareTo(Point other) {
            double a1 = Math.atan2(y, x);
            double a2 = Math.atan2(y, x);
            if (a1 < a2) {
                return -1;
            } else {
                return 1;
            }
        }
        
        public double angleTo(Point other) {
            double a1 = x * other.y - y * other.x;
            double a2 = x * other.x + y * other.y;
            return Math.abs(Math.atan2(a1, a2));
        }
    }
    
    static class EndOfFileRuntimeException extends RuntimeException {
        private static final long serialVersionUID = -8565341110209207657L; }
    
    public static class IOFast {
        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private PrintWriter out = new PrintWriter(System.out);

        void setFileIn(String ins) throws IOException { in.close(); in = new BufferedReader(new FileReader(ins)); }
        void setFileOut(String outs) throws IOException { out.flush(); out.close(); out = new PrintWriter(new FileWriter(outs)); }
        void setFileIO(String ins, String outs) throws IOException { setFileIn(ins); setFileOut(outs); }

        private static int pos, readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static char[] str = new char[500*8*2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; isLineSep['\r'] = isLineSep['\n'] = true; }
        public int read() throws IOException { if(pos >= readLen) { pos = 0; readLen = in.read(buffer); if(readLen <= 0) { throw new EndOfFileRuntimeException(); } } return buffer[pos++]; }
        public int nextInt() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; int ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
        public long nextLong() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); int i = 0; long ret = 0; if(str[0] == '-') { i = 1; } for(; i < len; i++) ret = ret * 10 + str[i] - '0'; if(str[0] == '-') { ret = -ret; } return ret; }
        public char nextChar() throws IOException { while(true) { final int c = read(); if(!isSpace[c]) { return (char)c; } } }
        int reads(int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } if(str.length == len) { char[] rep = new char[str.length * 3 / 2]; System.arraycopy(str, 0, rep, 0, str.length); str = rep; } str[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
        int reads(char[] cs, int len, boolean[] accept) throws IOException { try { while(true) { final int c = read(); if(accept[c]) { break; } cs[len++] = (char)c; } } catch(EndOfFileRuntimeException e) { ; } return len; }
        public char[] nextLine() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isLineSep); try { if(str[len-1] == '\r') { len--; read(); } } catch(EndOfFileRuntimeException e) { ; } return Arrays.copyOf(str, len); }
        public String nextString() throws IOException { return new String(next()); }
        public char[] next() throws IOException { int len = 0; str[len++] = nextChar(); len = reads(len, isSpace); return Arrays.copyOf(str, len); }
        public int next(char[] cs) throws IOException { int len = 0; cs[len++] = nextChar(); len = reads(cs, len, isSpace); return len; }
        public double nextDouble() throws IOException { return Double.parseDouble(nextString()); }
        public long[] nextLongArray(final int n) throws IOException { final long[] res = new long[n]; for(int i = 0; i < n; i++) { res[i] = nextLong(); } return res; }
        public int[] nextIntArray(final int n) throws IOException { final int[] res = new int[n]; for(int i = 0; i < n; i++) { res[i] = nextInt(); } return res; }
        public int[][] nextIntArray2D(final int n, final int k) throws IOException { final int[][] res = new int[n][]; for(int i = 0; i < n; i++) { res[i] = nextIntArray(k); } return res; }
        public int[][] nextIntArray2DWithIndex(final int n, final int k) throws IOException { final int[][] res = new int[n][k+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < k; j++) { res[i][j] = nextInt(); } res[i][k] = i; } return res; }
        public double[] nextDoubleArray(final int n) throws IOException { final double[] res = new double[n]; for(int i = 0; i < n; i++) { res[i] = nextDouble(); } return res; }
    }
    
    public static class FastScanner {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }
        
        public FastScanner(String fileName) {
            try {
                br = new BufferedReader(new FileReader(fileName));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        
        public String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
            
            return st.nextToken();
        }
        
        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
                return "";
            }
        }
        
        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
        
    }
    
}