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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.Map;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Queue;
import java.util.ArrayDeque;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author I_love_PloadyFree
 */
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);
		TaskD solver = new TaskD();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskD {
		private int n;
		private int m;
		private int k;
		private boolean[][] wall;
		private int[] dx = MiscUtils.DX4;
		private int[] dy = MiscUtils.DY4;

		public void solve(int testNumber, InputReader in, OutputWriter out) {
			input(in);

			DSU dsu = new DSU(n, m);
			boolean[][] used = new boolean[n][m];
			Map<Integer, Integer> answers = new HashMap<>(n);

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (wall[i][j] || used[i][j]) continue;
					used[i][j] = true;

					int wallCount = 0;
					Queue<IntPair> q = new ArrayDeque<>();
					q.add(new IntPair(i, j));
					while (!q.isEmpty()) {
						IntPair cur = q.poll();

						for (int k = 0; k < 4; k++) {
							int ii = cur.first + dx[k];
							int jj = cur.second + dy[k];

							if (used[ii][jj]) continue;

							if (wall[ii][jj]) {
								wallCount++;
							} else {
								dsu.unite(i, j, ii, jj);
								q.add(new IntPair(ii, jj));
								used[ii][jj] = true;
							}
						}
					}

					answers.put(dsu.findParent(i, j), wallCount);
				}
			}

			for (int i = 0; i < k; i++)
				out.printLine(answers.get(dsu.findParent(in.readInt() - 1, in.readInt() - 1)));
		}

		private void input(InputReader in) {
			n = in.readInt();
			m = in.readInt();
			k = in.readInt();

			wall = new boolean[n][m];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++)
					wall[i][j] = in.readCharacter() == '*';
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

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

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

		public void printLine(int i) {
			writer.println(i);
		}

	}

	static class DSU {
		private final int n;
		private final int m;
		private final int[] a;

		public DSU(int n, int m) {
			this.n = n;
			this.m = m;
			a = new int[n * m];
			for (int i = 0; i < a.length; i++)
				a[i] = i;
		}

		public int findParent(int i, int j) {
			return findParent(getIndex(i, j));
		}

		private int findParent(int v) {
			if (a[v] == v) return v;
			return a[v] = findParent(a[v]);
		}

		public void unite(int i1, int j1, int i2, int j2) {
			unite(getIndex(i1, j1), getIndex(i2, j2));
		}

		private void unite(int v1, int v2) {
			int p1 = findParent(v1);
			int p2 = findParent(v2);
			a[p1] = p2;
		}

		private int getIndex(int i, int j) {
			return m * i + j;
		}

	}

	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 readInt() {
			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 boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return isWhitespace(c);
		}

		public static boolean isWhitespace(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public char readCharacter() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			return (char) c;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);

		}

	}

	static class IntPair implements Comparable<IntPair> {
		public final int first;
		public final int second;

		public IntPair(int first, int second) {
			this.first = first;
			this.second = second;
		}


		public String toString() {
			return "(" + first + "," + second + ")";
		}


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

			IntPair intPair = (IntPair) o;

			return first == intPair.first && second == intPair.second;

		}


		public int hashCode() {
			int result = first;
			result = 31 * result + second;
			return result;
		}

		public int compareTo(IntPair o) {
			if (first < o.first)
				return -1;
			if (first > o.first)
				return 1;
			if (second < o.second)
				return -1;
			if (second > o.second)
				return 1;
			return 0;
		}

	}

	static class MiscUtils {
		public static final int[] DX4 = {1, 0, -1, 0};
		public static final int[] DY4 = {0, -1, 0, 1};

	}
}

