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.math.*;
import java.util.*;

public class D {

  static BufferedReader in;
  static PrintWriter out;
  static StringTokenizer stk;

  public static void main(String[] args) throws Exception {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(new OutputStreamWriter(System.out));

    preproc();

    /** Choose single or multiple */

    single(0);
    // multiple();

    out.flush();
  }

  static void preproc() {
    // add any preprocessing valid for all tests here
    //
  }

  static void single(int testId) throws Exception {
    // add code here
    //
    int n = ni();
    int m = ni();
    int k = ni();

    char[][] g = new char[n][];
    int[][] v = new int[n][m];
    for (int i = 0; i < n; i++)
      g[i] = ns().toCharArray();
    for (int i = 0; i < k; i++) {
      int r = ni() - 1;
      int c = ni() - 1;
      if (v[r][c] == 0)
        proc(r, c, g, v);
      println("" + v[r][c]);
    }
  }

  static class Pair {

    public int f;
    public int s;

    public Pair(int f, int s) {
      this.f = f;
      this.s = s;
    }
  }

  static void proc(int r, int c, char[][] g, int[][] v) {
    Queue<Pair> q = new ArrayDeque<>();
    List<Pair> cc = new ArrayList<>();


    int[][] dirs = { { 0, 1 }, { 0, -1 }, { 1, 0 }, { -1, 0 } };

    int res = 0;
    q.add(new Pair(r, c));
    v[r][c] = -1;
    cc.add(new Pair(r, c));
    while (!q.isEmpty()) {
      Pair x = q.poll();
      for (int[] dir : dirs) {
        int tr = x.f + dir[0];
        int tc = x.s + dir[1];
        if (v[tr][tc] == -1) {
          continue;
        }
        if (g[tr][tc] == '*')
          res++;
        else {
          q.add(new Pair(tr, tc));
          v[tr][tc] = -1;
          cc.add(new Pair(tr, tc));
        }
      }
    }
    final int res2 = res;
    cc.forEach(p -> {
      v[p.f][p.s] = res2;
    });
  }

  static void multiple() throws Exception {
    // multiple tests in single file
    int T = ni();
    for (int t = 0; t < T; t++) {
      single(t);
    }
  }

  static void printf(String format, Object... args) {
    out.printf(format, args);
  }

  static void println(String string) {
    out.println(string);
  }

  static long toL(String s) {
    return Long.parseLong(s);
  }

  static int toI(String s) {
    return Integer.parseInt(s);
  }

  static double toD(String s) {
    return Double.parseDouble(s);
  }

  static long toL(BigInteger n) {
    return n.longValue();
  }

  static BigInteger toBI(long n) {
    return BigInteger.valueOf(n);
  }

  static List<Integer> newli() {
    return new ArrayList<Integer>();
  }

  static List<Long> newll() {
    return new ArrayList<Long>();
  }

  static void nia(int[] a, int n) throws Exception {
    for (var i = 0; i < n; i++) {
      a[i] = ni();
    }
  }

  static void nla(long[] a, int n) throws Exception {
    for (var i = 0; i < n; i++) {
      a[i] = nl();
    }
  }

  static void nia(List<Integer> a, int n) throws Exception {
    for (var i = 0; i < n; i++) {
      a.add(ni());
    }
  }

  static void nla(List<Long> a, int n) throws Exception {
    for (var i = 0; i < n; i++) {
      a.add(nl());
    }
  }

  static int ni() throws Exception {
    while (stk == null || !stk.hasMoreTokens()) {
      stk = new StringTokenizer(in.readLine());
    }
    return Integer.parseInt(stk.nextToken());
  }

  static long nl() throws Exception {
    while (stk == null || !stk.hasMoreTokens()) {
      stk = new StringTokenizer(in.readLine());
    }
    return Long.parseLong(stk.nextToken());
  }

  static double nd() throws Exception {
    while (stk == null || !stk.hasMoreTokens()) {
      stk = new StringTokenizer(in.readLine());
    }
    return Double.parseDouble(stk.nextToken());
  }

  static String ns() throws Exception {
    while (stk == null || !stk.hasMoreTokens()) {
      stk = new StringTokenizer(in.readLine());
    }
    return stk.nextToken();
  }

  static int min(int a, int b) {
    return a < b ? a : b;
  }

  static int max(int a, int b) {
    return a > b ? a : b;
  }

  static long min(long a, long b) {
    return a < b ? a : b;
  }

  static long max(long a, long b) {
    return a > b ? a : b;
  }

  static double min(double a, double b) {
    return a < b ? a : b;
  }

  static double max(double a, double b) {
    return a > b ? a : b;
  }

  static int gcd(int a, int b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }

  static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    }
    return gcd(b, a % b);
  }
}
