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
/**
 * I am Resonator.
 */

// Still TLE??? Let's not create too much Pair instances and instead use integer
// Still TLE?? Let's try char[][] instead of String[]
// TLE? Okay let's try StringBuilder
// Minor bug fix in BFS
// Finally let's try with Bfs or I'm gonna have to give up Java
// Okay let's reduce stack memory consumption. If this doesn't work, will move to BFS as last resort.
// Let's reduce stack invocations
// Let's re-retry with increased stack size
// Let's retry same code with Fast I/O

import java.io.*;
import java.util.*;

public class Main {
	static int n, m, k;
	static int[][] gridVal;
	static String[] grid;
	static char[][] gridChar;
	static HashMap<Integer, Integer> ccpToCount;
	static boolean[][] visited;
	static ArrayList<Pair> dotPoints;
	static ArrayList<Integer> connectedComponents;
	static Queue<Pair> queue;

	public static class FastInput {
		BufferedReader  br;
		StringTokenizer st;

		public FastInput() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws IOException {
			while (st == null || !st.hasMoreTokens()) {
				st = new StringTokenizer(br.readLine());
			}

			return st.nextToken();
		}

		String nextLine() throws IOException {
			return br.readLine();
		}

		int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
	}

	private static class Pair
	{
		private int first, second;
		public Pair(int x, int y)
		{
			first = x;
			second = y;
		}

		public int getFirst() {
			return first;
		}

		public int getSecond() {
			return second;
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public boolean equals(Object o) {
			Pair pair = (Pair) o;
			return first == pair.getFirst() &&
					second == pair.getSecond();
		}

		/**
		 * {@inheritDoc}
		 */
		@Override
		public int hashCode() {
			return Objects.hash(first, second);
		}
	}

	private static int getValueForGridPoint(int i, int j)
	{
		if (i < 0 || j < 0 || i >= gridChar.length || j >= gridChar[0].length) {
			return 0;
		}
		if (gridChar[i][j] == '*') {
			return 1;
		}
		else {
			return 0;
		}
	}

	private static ArrayList<Pair> processGrid()
	{
		ArrayList<Pair> dotPoints = new ArrayList<>();
		for (int i = 0; i < gridChar.length; i++) {
			for (int j = 0; j < gridChar[i].length; j++) {
				if (gridChar[i][j] == '.') {
					dotPoints.add(new Pair(i, j));
					gridVal[i][j] =
							getValueForGridPoint(i - 1, j) +
							getValueForGridPoint(i + 1, j) +
							getValueForGridPoint(i, j - 1) +
							getValueForGridPoint(i, j + 1);
				}
			}
		}
		return dotPoints;
	}

	private static boolean isSafeToVisit(String[] grid, boolean[][] visited, int i, int j)
	{
		if (i < 0 || j < 0 || i >= grid.length || j >= grid[0].length() || visited[i][j] || grid[i].charAt(j) == '*') {
			return false;
		}

		return true;
	}

	private static int tryDfsAndGetTotalCountForConnectedComp(int i, int j)
	{
		visited[i][j] = true;
		connectedComponents.add(i*m+j);
		int count = gridVal[i][j];

		if (isSafeToVisit(grid, visited, i-1, j)) {
			count += tryDfsAndGetTotalCountForConnectedComp(i-1, j);
		}
		if (isSafeToVisit(grid, visited, i+1, j)) {
			count += tryDfsAndGetTotalCountForConnectedComp(i+1, j);
		}
		if (isSafeToVisit(grid, visited, i, j-1)) {
			count += tryDfsAndGetTotalCountForConnectedComp(i, j-1);
		}
		if (isSafeToVisit(grid, visited, i, j+1)) {
			count += tryDfsAndGetTotalCountForConnectedComp(i, j+1);
		}

		return count;
	}

	private static int tryBfsAndGetTotalCountForConnectedComp(int initi, int initj)
	{
		int count = 0;
		queue = new LinkedList<>();
		queue.add(new Pair(initi, initj));

		while (!queue.isEmpty()) {
			Pair p = queue.poll();
			int i = p.getFirst();
			int j = p.getSecond();
			if (visited[i][j]) {
				continue;
			}
			connectedComponents.add(i*m+j);

			visited[i][j] = true;
			count += gridVal[i][j];

			if (isSafeToVisit(grid, visited, i-1, j)) {
				queue.add(new Pair(i-1, j));
			}
			if (isSafeToVisit(grid, visited, i+1, j)) {
				queue.add(new Pair(i+1, j));
			}
			if (isSafeToVisit(grid, visited, i, j-1)) {
				queue.add(new Pair(i, j-1));
			}
			if (isSafeToVisit(grid, visited, i, j+1)) {
				queue.add(new Pair(i, j+1));
			}
		}

		return count;
	}

	private static class MyStackLimitIncreasedThread implements Runnable {
		public void run()
		{
			try {
				FastInput fi = new FastInput();
				PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out));

				n = fi.nextInt();
				m = fi.nextInt();
				k = fi.nextInt();
				gridVal = new int[n][m];
				grid = new String[n];
				gridChar = new char[n][m];
				ccpToCount = new HashMap<>();
				visited = new boolean[n][m];
				for (int i = 0; i < n; i++) {
					grid[i] = fi.nextLine();
					gridChar[i] = grid[i].toCharArray();
				}

				dotPoints = processGrid();

				connectedComponents = new ArrayList<>();
				for (Pair dotPoint : dotPoints) {
					if (visited[dotPoint.getFirst()][dotPoint.getSecond()]) {
						continue;
					}

					//int count = tryDfsAndGetTotalCountForConnectedComp(dotPoint.getFirst(), dotPoint.getSecond());
					int count = tryBfsAndGetTotalCountForConnectedComp(dotPoint.getFirst(), dotPoint.getSecond());
					for (Integer dotPointConnected : connectedComponents) {
						ccpToCount.put(dotPointConnected, count);
					}
					connectedComponents.clear();
				}

				StringBuilder sb = new StringBuilder();
				for (int i = 0; i < k; i++) {
					int x, y;
					x = fi.nextInt();
					y = fi.nextInt();
					sb.append(ccpToCount.get((x - 1)*m + y - 1) + "\n");
				}

				pw.print(sb);
				pw.close();
			} catch (IOException e) {
			}
		}
	}

    public static void main(String[] args) throws IOException {
		//Thread t = new Thread(null, new MyStackLimitIncreasedThread(), "MyStackLimitIncreasedThread", (1 << 31));
		Thread t = new Thread(null, new MyStackLimitIncreasedThread(), "MyStackLimitIncreasedThread");
		t.start();
		try {
			t.join();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
