#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;
  string str[505];
  int i;
  for (i = 0; i <= h - 1; i++) {
    cin >> str[i];
  }
  int arr[505][505] = {0}, arr1[505][505] = {0}, j;
  for (i = 1; i <= h; i++) {
    for (j = 2; j <= w; j++) {
      char ch = str[i - 1][j - 1];
      char prev = str[i - 1][j - 2];
      if (ch == '#') {
        arr[i][j] = arr[i][j - 1];
      } else {
        if (ch == prev)
          arr[i][j] = arr[i][j - 1] + 1;
        else
          arr[i][j] = arr[i][j - 1];
      }
    }
  }
  for (j = 1; j <= w; j++) {
    for (i = 2; i <= h; i++) {
      char ch = str[i - 1][j - 1];
      char prev = str[i - 2][j - 1];
      if (ch == '#')
        arr1[i][j] = arr1[i - 1][j];
      else if (ch == prev)
        arr1[i][j] = arr1[i - 1][j] + 1;
      else
        arr1[i][j] = arr1[i - 1][j];
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int r1, c1, r2, c2, ans = 0;
    scanf("%d%d", &r1, &c1);
    scanf("%d%d", &r2, &c2);
    for (i = r1; i <= r2; i++) {
      char cur = str[i - 1][c1 - 1];
      char prev = (c1 == 1) ? ('#') : str[i - 1][c1 - 2];
      ans += (arr[i][c2] - arr[i][c1 - 1]);
      if (cur == prev && cur == '.') ans--;
    }
    for (j = c1; j <= c2; j++) {
      char cur = str[r1 - 1][j - 1];
      char prev = (r1 == 1) ? ('#') : str[r1 - 2][j - 1];
      ans += (arr1[r2][j] - arr1[r1 - 1][j]);
      if (cur == prev && cur == '.') ans--;
    }
    printf("%d\n", ans);
  }
  return 0;
}
